in reply to Sorting HoHoA based on Length of Second Key
my @sorted = map {substr $_,2} sort map { pack 'na*', length((%{$HoHoA{$_}})[0]), $_ } keys %HoHoA;
This is a Guttman-Rosler Transform - it packs the length of the first key of each inner hash (assumption: each inner hash has all keys the same length - you can't guarantee to get an AA.. key rather than a BB.. key as the `first') into 2 bytes in network order (assumption: no inner hash key has length >65535) and appends the main hash key.
The resulting list of strings can be sorted by the fast default sort and the substr throws away the two-byte length marker, leaving just the keys.
HTH
Jonathan
|
|---|