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 = @ipaddr;
for( $ctr = 0 ; $ctr < $arrsize ; $ctr++ )
{
$ip_intf_hash{ $ipaddr[$ctr] } = "";
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,3.3.3.3,1.1.1.1
2.2.2.2 : 3.3.3.3 : 1.1.1.1 :
You entered the IP addresses:
1.1.1.1 : 3.3.3.3 : 2.2.2.2 :
Any ideas on why the hash elements get reversed?
Thanks.
Neelay.
- hash values are printed in reverse order neelay thaker
- Re: hash values are printed in reverse order Riehm Stephen
