P0w3rK!d has asked for the wisdom of the Perl Monks concerning the following question:
The entries are placed in seqential order such as:# build hash while() { ... $hshFoo{$key1}{$key2} = $strFileName; ... # key1 is a number # key2 is a sequential number }
When I dump the hash, the keys come out as follows:$hshFoo{2823}{0} = 2823_0.xml $hshFoo{2823}{1} = 2823_1.xml $hshFoo{2823}{2} = 2823_2.xml $hshFoo{2823}{3} = 2823_3.xml
The files were originally placed in the hash from a sorted array. Are the keys not in order within the hash or does Perl just grab the keys in any order?foreach $key1 (keys %hshFoo) { foreach $key2 (keys %{$hshFoo{$key1}}) { print "$key1/$key2 => $hshFoo{$key1}{$key2}\n"; } } ... Output: 2823/1 => 2823_1.xml 2823/0 => 2823_0.xml 2823/3 => 2823_3.xml 2823/2 => 2823_2.xml ... I expected: 2823/0 => 2823_0.xml 2823/1 => 2823_1.xml 2823/2 => 2823_2.xml 2823/3 => 2823_3.xml
-P0w3rK!d
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Hash key ordering question
by thelenm (Vicar) on May 07, 2003 at 18:13 UTC | |
by P0w3rK!d (Pilgrim) on May 07, 2003 at 18:17 UTC | |
Re: Hash key ordering question
by artist (Parson) on May 07, 2003 at 18:20 UTC | |
Re: Hash key ordering question
by jkenneth (Pilgrim) on May 07, 2003 at 18:52 UTC | |
by hardburn (Abbot) on May 07, 2003 at 19:22 UTC | |
Re: Hash key ordering question
by jgallagher (Pilgrim) on May 07, 2003 at 18:30 UTC | |
by shemp (Deacon) on May 07, 2003 at 18:43 UTC | |
by P0w3rK!d (Pilgrim) on May 07, 2003 at 19:18 UTC | |
by jgallagher (Pilgrim) on May 07, 2003 at 21:55 UTC |