Hi, I don't want to spam the chatterbox anymore, but I am still stuck on how to sort a nested hash within a hash of hashes.
# here's my test hash my %hash; $hash{"Rock Bands"}{"Smashing Pumpkins"} = "5 stars"; $hash{"Rock Bands"}{"Aerosmith"} = "5 stars"; $hash{"Rock Bands"}{"Foo Fighters"} = "5 stars"; $hash{"Pop Bands"}{"Duran Duran"} = "5 stars"; $hash{"Pop Bands"}{"Blondie"} = "5 stars"; foreach my $key (sort keys %hash) { # this bit sorts ok print "KEY: $key \n"; while (my ($nestedKey, $value) = each %{ $hash{$key} } ) { # but I can't work out how to sort this iteration print "nested key: $nestedKey \n"; } print "-------\n"; }
This returns:
KEY: Pop Bands
nested key: Duran Duran
nested key: Blondie
-------
KEY: Rock Bands
nested key: Foo Fighters
nested key: Smashing Pumpkins
nested key: Aerosmith
-------
But I would like it to return:
KEY: Pop Bands
nested key: Blondie
nested key: Duran Duran
-------
KEY: Rock Bands
nested key: Aerosmith
nested key: Foo Fighters
nested key: Smashing Pumpkins
-------
Any suggestions would be welcome, thanks!!
In reply to Sorting hash of hashes by tweak
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |