Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm using the following code to sort my hash of hashes by key. I'm trying to get the numerical keys in order for printing. see below:$VAR1 = 'cycVolumeSetActivity'; $VAR2 = { '1' => 'reconstruct', '2' => 'initialize', '3' => 'verify', '10' => 'mirrorCreate', '4' => 'spareTest', '11' => 'migration', '5' => 'scheduledReconstruct', '12' => 'expansion', '6' => 'scheduledInitialize', '7' => 'scheduledVerify', '8' => 'scheduledSpareTest', '9' => 'mirrorBreak' };
It's not sorting them numerically, does anyone know why?foreach my $key ( keys %event_hash ) { print "$key: { "; for my $key2 ( sort keys %{ $event_hash{$key} } ) { sort { keys %{$event_hash{$key}{$b}} cmp keys %{$event_hash{$key}{ +$a}} } keys %event_hash; print "$key2=$event_hash{$key}{$key2} "; } print "}\n"; }
Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: Numerical sorting issues with a hash of hashes
by merlyn (Sage) on Jul 22, 2003 at 14:31 UTC | |
by Anonymous Monk on Jul 22, 2003 at 14:39 UTC | |
by Lachesis (Friar) on Jul 22, 2003 at 15:05 UTC | |
|
Re: Numerical sorting issues with a hash of hashes
by simonm (Vicar) on Jul 22, 2003 at 15:04 UTC | |
|
Re: Numerical sorting issues with a hash of hashes
by Kageneko (Scribe) on Jul 22, 2003 at 14:36 UTC | |
|
Re: Numerical sorting issues with a hash of hashes
by BrowserUk (Patriarch) on Jul 22, 2003 at 21:37 UTC |