http://qs1969.pair.com?node_id=376714


in reply to Re^3: sorting a complex multidimensional hash
in thread sorting a complex multidimensional hash

That's not too hard to do:

print for map{ my( $n1, $a1, $n2, $a2, $value ) = unpack 'N A4 N A4 A*', $_; "{$n1.$a1}{$n2.$a2} => $value" } sort map { my $key1 = $_; map { pack 'N A4 N A4 A*', split( '\.', $key1 ), split( '\.', $_ ), $hash{ $key1 }{ $_ } } keys %{ $hash{ $_ } }; } keys %hash;

but it does introduce a limitation.

As coded above, the character part of the keys is limited to 4 characters each. They can be shorter but no longer. If this isn't long enough, you must adjust the formats ( 'N A4 N A4 A*' ) to say 'N A10 N A10 A*' for up to 10 chars, in both the pack and the unpack.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon