in reply to Hash key ordering question

If you want them in numerical order rather than the order you put them in, you could also do:
foreach $key1 (sort keys %hshFoo) { foreach $key2 (sort keys %{$hshFoo{$key1}}) { print "$key1/$key2 => $hshFoo{$key1}{$key2}\n"; } }

Replies are listed 'Best First'.
Re: Re: Hash key ordering question
by shemp (Deacon) on May 07, 2003 at 18:43 UTC
    that will actually sort in string comparison order (the default for sort). for numeric order, you want:
    ... foreach $key1 (sort {$a <=> $b} keys %hshFoo) { ...
      This is what I was looking for. I was trying to do something with Tie::IxHash the last 10 minutes.
      my $t = Tie::IxHash->new(%hshFoo); my @keys = $t->Keys; $t->Reorder(@keys); $t->SortByKey; untie %hshFoo; ...or something

      -P0w3rK!d

      Thanks. That completely slipped my mind.