#! perl -slw use strict; use Data::Dumper; use List::Util qw[ shuffle ]; ## An array of properties my @props = map{ "prop$_" } 1 .. 10; ## Gerate some test data my %things = map { +"thing$_" => { map{ $_ => int rand 1000 } ( shuffle @props )[ 0 .. 4 ] } } '0001' .. '3000'; ## Create a hash of indexes sorted by the the values of the properties my %orderings = map{ my $prop = $_; $prop => [ sort { $things{ $a }{ $_ } <=> $things{ $b }{ $_ } } map{ exists $things{ $_ }{ $prop } ? $_ : () } keys %things ] } @props; ## Display everything, in every order for my $prop ( @props ) { print "\nThings ordered by $prop\n"; for my $thing ( @{ $orderings{ $prop } } ) { print $thing, ' => { ', join( '', map{ sprintf "%6.6s: %3.3s, ", exists $things{ $thing }{ $_ } ? ( $_, $things{ $thing }{ $_ } ) : ( '', '' ) } @props ) . ' }'; } }