hash values are printed in reverse order
[email protected] (neelay thaker) Thu, 22 Sep 2005 10:59:17 -0700
| Newsgroups | perl.scripts |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_7167_1393485.1127411957387
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
Hi,
when I parse a list of comma separated IP addresses, put them into an array
and then transfer the elements of the array into a hash, the hash elements
get printed in reverse order as compared to the array and the input. The
following code and output will make this problem clear.
The code snipet is this-
$arrsize =3D @ipaddr;
for( $ctr =3D 0 ; $ctr < $arrsize ; $ctr++ )
{
$ip_intf_hash{ $ipaddr[$ctr] } =3D "";
print $ipaddr[$ctr];
print " : ";
}
print "\n";
print "You entered the IPaddresses:\n";
foreach $nfr ( keys %ip_intf_hash )
{
print "$nfr : ";
}
print "\n";
The output looks like this-
Enter the IP addresses: 2.2.2.2 <http://2.2.2.2>,3.3.3.3 <http://3.3.3.3>,
1.1.1.1 <http://1.1.1.1>
2.2.2.2 <http://2.2.2.2> : 3.3.3.3 <http://3.3.3.3> : 1.1.1.1<http://1.1.1.=
1>:
You entered the IP addresses:
1.1.1.1 <http://1.1.1.1> : 3.3.3.3 <http://3.3.3.3> : 2.2.2.2<http://2.2.2.=
2>:
Any ideas on why the hash elements get reversed?
Thanks.
Neelay.
------=_Part_7167_1393485.1127411957387
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
Hi,<br>
when I parse a list of comma separated IP addresses, put them into an
array and then transfer the elements of the array into a hash, the hash
elements get printed in reverse order as compared to the array and the
input. The following code and output will make this problem clear.<br>
The code snipet is this-<br>
&nb=
sp; $arrsize =3D @ipaddr;<br>
&nb=
sp;
for( $ctr =3D 0 ; $ctr < $arrsize ; $ctr++ )<br>
&nb=
sp; {<br>
&nb=
sp;
$ip_intf_hash{ $ipaddr[$ctr] } =3D "";<br>
&nb=
sp;
print $ipaddr[$ctr];<br>
&nb=
sp;
print " : ";<br>
&nb=
sp; }<br>
&nb=
sp; print "\n";<br>
&nb=
sp;
print "You entered the IPaddresses:\n";<br>
&nb=
sp; foreach $nfr ( keys %ip_intf_hash )<br>
&nb=
sp; {<br>
&nb=
sp;
print "$nfr : ";<br>
&nb=
sp; }<br>
&nb=
sp; print "\n";<br>
<br>
The output looks like this-<br>
&nb=
sp;
Enter the IP addresses: <a href=3D"http://2.2.2.2">2.2.2.2</a>,<a href=3D"h=
ttp://3.3.3.3">3.3.3.3</a>,<a href=3D"http://1.1.1.1">1.1.1.1</a><br>
&nb=
sp; <a href=3D"http://2.2.2.2">2.2.2.2</a> : <a href=3D"http://3.3.3.=
3">3.3.3.3</a> : <a href=3D"http://1.1.1.1">1.1.1.1</a> :<br>
&nb=
sp; You entered the IP addresses:<br>
&nb=
sp; <a href=3D"http://1.1.1.1">1.1.1.1</a> : <a href=3D"http://3.3.3.3">3.3=
.3.3</a> : <a href=3D"http://2.2.2.2">2.2.2.2</a> :<br>
Any ideas on why the hash elements get reversed?<br>
Thanks.<br>
<br>
Neelay.<br>
------=_Part_7167_1393485.1127411957387--