Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Hash key ordering question

by jgallagher (Pilgrim)
on May 07, 2003 at 18:30 UTC ( #256344=note: print w/replies, xml ) Need Help??

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


      Thanks. That completely slipped my mind.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://256344]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2020-02-27 05:42 GMT
Find Nodes?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?

    Results (118 votes). Check out past polls.