in reply to extracting values from sort

You don't need the reverse function, swap $a and $b around


"We are all prompted by the same motives, all deceived by the same fallacies, all animated by hope, obstructed by danger, entangled by desire, and seduced by pleasure." - Samuel Johnson

Replies are listed 'Best First'.
RE: RE: extracting values from sort
by chromatic (Archbishop) on Oct 05, 2000 at 07:07 UTC
    The reverse isn't reversing the sort, it's reversing the order of the elements of the list returned by the sliced sort.

    Check the parenthesis.

RE: RE: extracting values from sort
by agoth (Chaplain) on Oct 04, 2000 at 14:36 UTC
    ??
    swapping $a and $b and dropping reverse gives me 34, 56 ?
      Are you sure? On my box this is the same...
      #!/usr/local/bin/perl $num=5; my %hash = ('1' => 12, '2' => 34, '3' => 56, '4' => 2); @values = reverse ((sort {$a <=> $b} values %hash)[0..--$num]); print @values, "\n"; $num=5; @values = (sort {$b <=> $a} values %hash)[0..--$num]; print @values, "\n"; -----> /home/jonathan> z 5634122 5634122
      "We are all prompted by the same motives, all deceived by the same fallacies, all animated by hope, obstructed by danger, entangled by desire, and seduced by pleasure." - Samuel Johnson
        :-), if num is 5 and theres only 4 in the hash it should be.
        try dropping num to a number lower than the number of keys so you get a subset.