in reply to •Re: Numerical sorting issues with a hash of hashes
in thread Numerical sorting issues with a hash of hashes

hmm...I cleaned it up with the follwoing code:
foreach my $key ( keys %event_hash ) { print $key, "\n"; for my $key2 ( keys %{ $event_hash{$key} } ) { sort { $a <=> $b } print "$key2=$event_hash{$key}{$key2}\n"; } print "\n"; }
and the output still isn't sorted:

OUTPUT

cycVolumeSetActivityState 1=started 2=startedAutofix 3=completed 10=deleted 4=completedWithMiscompares 11=priorityChanged 5=abortedDueToIOError 20=running 12=scheduled 6=abortedDueToIOErrorWithMiscompares 21=aborted 13=modified 7=abortedByOperator 14=failedToStart 8=abortedByOperatorWithMiscompares 9=failed 15=abortedNoMemory 16=restarted 17=suspended 18=resumed 19=stopped

Replies are listed 'Best First'.
Re: Re: &bull;Re: Numerical sorting issues with a hash of hashes
by Lachesis (Friar) on Jul 22, 2003 at 15:05 UTC
    You need to call sort in your for condition It only needs a small change to sort out
    foreach my $key ( keys %event_hash ) { print $key, "\n"; for my $key2 ( sort { $a <=> $b } keys %{ $event_hash{$key} } ) { + print "$key2=$event_hash{$key}{$key2}\n"; } print "\n"; }