Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: sorting a complex multidimensional hash

by tilly (Archbishop)
on Jul 22, 2004 at 02:45 UTC ( [id://376446]=note: print w/replies, xml ) Need Help??


in reply to sorting a complex multidimensional hash

fast, flexible, stable sort gives a good way of sorting strings in the way that you want. That reduces this to being a problem of producing the list to sort.

Try this:

my @list = map {my $first = $_; map {"$first|$_"} keys %{$myhash{$firs +t}}} keys %myhash; sub XFORM { # Extract the sort key from $_[0] and return it. # This will often be written in-line # rather than as a real subroutine. } my @sorted= @list[ map { unpack "N", substr($_,-4) } sort map { XFORM($list[$_]) . pack "N", $_ } 0..$#list ]; foreach my $key (@sorted) { my ($first, $second) = split /\|/, $key; print "$first: $second: $myhash{$first}{$second}{'one'}\n"; }
(Untested code...)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-20 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found