[OAI-implementers] RE: Order of keys in hashes

Steve Sarapata ssarapat@enc.org
Wed, 25 Sep 2002 14:38:44 -0400


This is a multi-part message in MIME format.

------_=_NextPart_001_01C264C2.C6EDB068
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hashes don't maintain key order. To get them in sorted order try:

    foreach $i (sort keys(%afiliacao))
    {
    }


		-----Original Message-----
		From: oai-implementers-admin@oaisrv.nsdl.cornell.edu =
[mailto:oai-implementers-admin@oaisrv.nsdl.cornell.edu] On Behalf Of =
Ramon Martins Sodoma da Fonseca
		Sent: Wednesday, September 25, 2002 2:34 PM
		To: 'OAI Implementers'
		Subject: Order of keys in hashes

		Does anyone know why Perl changes the order of keys in a hash??
		I need the order to be the following:
		          my %afiliacao =3D (
		                        Nome    =3D> $tupla11[4],
		                        Sigla   =3D> $tupla11[5],
		                        Pais    =3D> $tupla11[6],
		                        UF      =3D> $tupla11[7],
		                        CNPJ    =3D> $tupla11[8],  **
		                        URL     =3D> $tupla11[9],

		instead of printing the order above in the XML, it prints the =
following:
		<Afiliacao>=20
		   <Nome>Biblioteca Digital de Teses e Disserta=E7=F5es</Nome>=20
		   <Sigla>BDTD</Sigla>=20
		   <CNPJ>123456</CNPJ>  **
		   <Pais>BRA</Pais>=20
		   <UF>DF</UF>=20
		   <URL>http://www.ibict.br/bdtd/</URL>=20
		</Afiliacao>=20

		................................................
		Ram=F3n Fonseca
		Design Gr=E1fico & Multim=EDdia
		Desenvolvimento Web
		ramal: 6443
		       6447
		................................................


------_=_NextPart_001_01C264C2.C6EDB068
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
6.0.6249.1">
<TITLE>RE: Order of keys in hashes</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><FONT COLOR=3D"#000080" SIZE=3D2 =
FACE=3D"Arial">Hashes don</FONT></SPAN><SPAN LANG=3D"en-us"><FONT =
COLOR=3D"#000080" SIZE=3D2 FACE=3D"Arial">&#8217;</FONT></SPAN><SPAN =
LANG=3D"en-us"><FONT COLOR=3D"#000080" SIZE=3D2 FACE=3D"Arial">t =
maintain</FONT></SPAN><SPAN LANG=3D"en-us"> <FONT COLOR=3D"#000080" =
SIZE=3D2 FACE=3D"Arial">key</FONT></SPAN><SPAN LANG=3D"en-us"> <FONT =
COLOR=3D"#000080" SIZE=3D2 FACE=3D"Arial">order. To get them in sorted =
order try:</FONT></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><FONT COLOR=3D"#000080" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp; foreach $i (sort =
keys(%</FONT></SPAN><SPAN LANG=3D"en-us"><FONT COLOR=3D"#000080" =
SIZE=3D2 FACE=3D"Arial">a</FONT></SPAN><SPAN LANG=3D"en-us"><FONT =
COLOR=3D"#000080" SIZE=3D2 FACE=3D"Arial">filiacao</FONT></SPAN><SPAN =
LANG=3D"en-us"><FONT COLOR=3D"#000080" SIZE=3D2 =
FACE=3D"Arial">))</FONT></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><FONT COLOR=3D"#000080" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp; {</FONT></SPAN><SPAN =
LANG=3D"en-us"></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><FONT COLOR=3D"#000080" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp; }</FONT></SPAN><SPAN =
LANG=3D"en-us"></SPAN></P>
<BR>
<UL><UL>
<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><FONT SIZE=3D2 =
FACE=3D"Tahoma">-----Original Message-----<BR>
</FONT></SPAN><SPAN LANG=3D"en-us"><B></B></SPAN><SPAN =
LANG=3D"en-us"><B><FONT SIZE=3D2 =
FACE=3D"Tahoma">From:</FONT></B></SPAN><SPAN LANG=3D"en-us"></SPAN><SPAN =
LANG=3D"en-us"><FONT SIZE=3D2 FACE=3D"Tahoma"> =
oai-implementers-admin@oaisrv.nsdl.cornell.edu [<A =
HREF=3D"mailto:oai-implementers-admin@oaisrv.nsdl.cornell.edu">mailto:oai=
-implementers-admin@oaisrv.nsdl.cornell.edu</A>]</FONT></SPAN><SPAN =
LANG=3D"en-us"><B></B></SPAN><SPAN LANG=3D"en-us"><B> <FONT SIZE=3D2 =
FACE=3D"Tahoma">On Behalf Of</FONT></B></SPAN><SPAN =
LANG=3D"en-us"></SPAN><SPAN LANG=3D"en-us"> <FONT SIZE=3D2 =
FACE=3D"Tahoma">Ramon Martins Sodoma da Fonseca<BR>
</FONT></SPAN><SPAN LANG=3D"en-us"><B></B></SPAN><SPAN =
LANG=3D"en-us"><B><FONT SIZE=3D2 =
FACE=3D"Tahoma">Sent:</FONT></B></SPAN><SPAN LANG=3D"en-us"></SPAN><SPAN =
LANG=3D"en-us"><FONT SIZE=3D2 FACE=3D"Tahoma"> Wednesday, September 25, =
2002 2:34 PM<BR>
</FONT></SPAN><SPAN LANG=3D"en-us"><B></B></SPAN><SPAN =
LANG=3D"en-us"><B><FONT SIZE=3D2 =
FACE=3D"Tahoma">To:</FONT></B></SPAN><SPAN LANG=3D"en-us"></SPAN><SPAN =
LANG=3D"en-us"><FONT SIZE=3D2 FACE=3D"Tahoma"> 'OAI Implementers'<BR>
</FONT></SPAN><SPAN LANG=3D"en-us"><B></B></SPAN><SPAN =
LANG=3D"en-us"><B><FONT SIZE=3D2 =
FACE=3D"Tahoma">Subject:</FONT></B></SPAN><SPAN =
LANG=3D"en-us"></SPAN><SPAN LANG=3D"en-us"><FONT SIZE=3D2 =
FACE=3D"Tahoma"> Order of keys in hashes</FONT></SPAN><SPAN =
LANG=3D"en-us"></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><FONT COLOR=3D"#008080" SIZE=3D2 =
FACE=3D"Andale Mono">Does anyone know why Perl changes the order of keys =
in a hash??</FONT></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><FONT COLOR=3D"#008080" SIZE=3D2 =
FACE=3D"Andale Mono">I need the order to be the =
following:</FONT></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#008080" SIZE=3D2 =
FACE=3D"Andale =
Mono">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my =
%afiliacao =3D (</FONT></B></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#008080" SIZE=3D2 =
FACE=3D"Andale =
Mono">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
Nome&nbsp;&nbsp;&nbsp; =3D&gt; $tupla11[4],</FONT></B></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#008080" SIZE=3D2 =
FACE=3D"Andale =
Mono">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
Sigla&nbsp;&nbsp; =3D&gt; $tupla11[5],</FONT></B></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#008080" SIZE=3D2 =
FACE=3D"Andale =
Mono">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
Pais&nbsp;&nbsp;&nbsp; =3D&gt; $tupla11[6],</FONT></B></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#008080" SIZE=3D2 =
FACE=3D"Andale =
Mono">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
UF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =3D&gt; =
$tupla11[7],</FONT></B></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#008080" SIZE=3D2 =
FACE=3D"Andale =
Mono">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
CNPJ&nbsp;&nbsp;&nbsp; =3D&gt; $tupla11[8],&nbsp; =
**</FONT></B></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#008080" SIZE=3D2 =
FACE=3D"Andale =
Mono">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
URL&nbsp;&nbsp;&nbsp;&nbsp; =3D&gt; $tupla11[9],</FONT></B></SPAN><SPAN =
LANG=3D"en-us"></SPAN><SPAN LANG=3D"en-us"></SPAN><SPAN =
LANG=3D"en-us"></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><FONT COLOR=3D"#008080" SIZE=3D2 =
FACE=3D"Andale Mono">instead of printing the order above in the XML, it =
prints the following:</FONT></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#800000" SIZE=3D2 =
FACE=3D"Andale Mono">&lt;Afiliacao&gt; </FONT></B></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#800000" SIZE=3D2 =
FACE=3D"Andale Mono">&nbsp;&nbsp; &lt;Nome&gt;Biblioteca Digital de =
Teses e Disserta=E7=F5es&lt;/Nome&gt; </FONT></B></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#800000" SIZE=3D2 =
FACE=3D"Andale Mono">&nbsp;&nbsp; &lt;Sigla&gt;BDTD&lt;/Sigla&gt; =
</FONT></B></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#800000" SIZE=3D2 =
FACE=3D"Andale Mono">&nbsp;&nbsp; &lt;CNPJ&gt;123456&lt;/CNPJ&gt;&nbsp; =
**</FONT></B></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#800000" SIZE=3D2 =
FACE=3D"Andale Mono">&nbsp;&nbsp; &lt;Pais&gt;BRA&lt;/Pais&gt; =
</FONT></B></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#800000" SIZE=3D2 =
FACE=3D"Andale Mono">&nbsp;&nbsp; &lt;UF&gt;DF&lt;/UF&gt; =
</FONT></B></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#800000" SIZE=3D2 =
FACE=3D"Andale Mono">&nbsp;&nbsp; &lt;URL&gt;<A =
HREF=3D"http://www.ibict.br/bdtd/">http://www.ibict.br/bdtd/</A>&lt;/URL&=
gt; </FONT></B></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#800000" SIZE=3D2 =
FACE=3D"Andale Mono">&lt;/Afiliacao&gt;</FONT></B></SPAN><SPAN =
LANG=3D"en-us"><B></B></SPAN><SPAN LANG=3D"en-us"><B> </B></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#008080" SIZE=3D2 =
FACE=3D"Andale =
Mono">................................................</FONT></B></SPAN><=
/P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#008080" SIZE=3D2 =
FACE=3D"Andale Mono">Ram=F3n Fonseca</FONT></B></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#008080" SIZE=3D2 =
FACE=3D"Andale Mono">Design Gr=E1fico &amp; =
Multim=EDdia</FONT></B></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#008080" SIZE=3D2 =
FACE=3D"Andale Mono">Desenvolvimento Web</FONT></B></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#008080" SIZE=3D2 =
FACE=3D"Andale Mono">ramal: 6443</FONT></B></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#008080" SIZE=3D2 =
FACE=3D"Andale Mono">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
6447</FONT></B></SPAN></P>

<P ALIGN=3DLEFT><SPAN LANG=3D"en-us"><B><FONT COLOR=3D"#008080" SIZE=3D2 =
FACE=3D"Andale =
Mono">................................................</FONT></B></SPAN><=
/P>
</UL></UL>
</BODY>
</HTML>
------_=_NextPart_001_01C264C2.C6EDB068--