in reply to Sorting a multidimensional hash by column

Hi piccard, I am assuming that you need to sort hashes of AAA, BBB...
The following works if my assumption is correct.
#!/usr/bin/perl use strict; use warnings; my($hash); $hash->{"AAA"}->{"KEY1"} = "VALUE1"; $hash->{"AAA"}->{"KEY2"} = "VALUE2"; $hash->{"AAA"}->{"KEY3"} = "VALUE3"; $hash->{"BBB"}->{"KEY1"} = "VALUEA"; $hash->{"BBB"}->{"KEY2"} = "VALUEB"; $hash->{"BBB"}->{"KEY3"} = "VALUEC"; for my $set (sort {$hash->{$a}->{"KEY2"} cmp $hash->{$b}->{"KEY2"}} (k +eys %{$hash})){ print "$set:\n"; for my $key (sort(keys %{$hash->{$set}})){ print "\t$key: $hash->{$set}->{$key}\n"; } }
The above returns
AAA: KEY1: VALUE1 KEY2: VALUE2 KEY3: VALUE3 BBB: KEY1: VALUEA KEY2: VALUEB KEY3: VALUEC
sort takes an optional code block which uses the package variables $a and $b for comparison of the members of the list.

Hope that helps

print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."