in reply to Sorting multi-hash values

I read from a delimited file and create a hash of a hash of an array.
See and that exactly is the problem :) Use an AoA and the sort will become trivial.

Update: Of course you can transform the data to an AoA first:
my @data; for $colour (sort keys %hash){ for $device (sort keys %{ $hash{$colour}}){ push @data, [ $colour, $device, $hash{$colour}{$device}[0] ] +; } } @data = reverse sort { $a->[2] <=> $b->[2] } @data;


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: Sorting multi-hash values
by naikonta (Curate) on Aug 22, 2007 at 18:32 UTC
    How did you consider to use reverse instead of $b->[2] <=> $a->[2]?

    Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

      Because I'm stoned.


      holli, /regexed monk/
        Well, that at least explains something ;-)

        Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

      Actually the 'reverse sort' combination is recognized by perl and optimized away for simple comparisons.

      Thus it's actually not a bad idea

      Isn't reverse sort optimized to do both operations at once?