On Oct 6, Rose, Jeff said:
I have been trying to sort a hash but I cannot figure it out for the life of me
I've fixed a bit of the formatting below...
my %message = ( $messageid => { From => $from, To => $to, To_Num => $num, Sub_IP => $ip, Subject => $subject, }, ... )
foreach (sort {$message{$_}->{'To_Num'}[$a] <=> $message{$_}->{'To_Num'}[$b]} keys (%message)) { }
foreach (sort {$message{$a} cmp $message{$b}} keys (%message)) {
foreach (sort {$message{$_}->{'To_Num'}[$a] <=> $message{$_}->{'To_Num'}[$b]} keys (%message)) {
You keep putting $a and $b all the way at the "end" of the things you're sorting. I don't think you actually know what $a and $b are. $a and $b represent two elements of the list you're sorting -- this means they're two keys from %message. This means the ONLY place it makes sense for them to be is $message{$a} and $message{$b}. To sort my the 'To_Num' field, then, you would do:
sort { $message{$a}{To_Num} <=> $message{$b}{To_Num} } keys %message -- Jeff "japhy" Pinyan % How can we ever be the sold short or RPI Acacia Brother #734 % the cheated, we who for every service http://www.perlmonks.org/ % have long ago been overpaid? http://princeton.pm.org/ % -- Meister Eckhart -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>