in reply to Return values from a key sorted hash

SavannahLion:

It's just like this:

#!/usr/bin/perl use strict; use warnings; my %tmp = ( a=>1, b=>2, c=>3 ); my @vals = @tmp{reverse sort keys %tmp}; print "@vals\n";

Which prints (on my system):

Roboticus@Roboticus-PC ~ $ perl t.pl 3 2 1

All the magic is in the single line:

my @vals = @tmp{reverse sort keys %tmp};

Basically, you're just returning the list of values from a hash slice:

...roboticus

Replies are listed 'Best First'.
Re^2: Return values from a key sorted hash
by BrowserUk (Patriarch) on Sep 10, 2010 at 22:23 UTC

    Why reverse? (And it ain;t "magic"!)

      BrowserUk:

      No real reason, just a demonstration. I just put in reverse for fun, intending to illustrate that you could put in any order.

      ...roboticus