in reply to Sorting HoHoA based on Length of Second Key
If you have no preference on the ordering of ties, then the ST part can be a bit simpler:print "$_ # Length ", length( ( keys %{ $HoHoA{ $_ } } )[ 0 ] ), "\n" for map $_->[ 0 ], sort { $a->[ 1 ] <=> $b->[ 1 ] || $a->[ 2 ] <=> $b->[ 2 ] } map [ $_, length( ( keys %{ $HoHoA{ $_ } } )[ 0 ] ), substr( $_, 3 ) + ], keys %HoHoA; __END__ set2 # Length 3 set3 # Length 3 set4 # Length 4 set1 # Length 7
These solutions assume that all the secondary hashes contain at least one key.map $_->[ 0 ], sort { $a->[ 1 ] <=> $b->[ 1 ] } map [ $_, length( ( keys %{ $HoHoA{ $_ } } )[ 0 ] ) ], keys %HoHoA;
the lowliest monk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sorting HoHoA based on Length of Second Key
by neversaint (Deacon) on Jul 27, 2005 at 06:19 UTC | |
by tlm (Prior) on Jul 27, 2005 at 06:37 UTC |