in reply to RE: extracting values from sort
in thread extracting values from sort

??
swapping $a and $b and dropping reverse gives me 34, 56 ?

Replies are listed 'Best First'.
RE: RE: RE: extracting values from sort
by Jonathan (Curate) on Oct 04, 2000 at 15:45 UTC
    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.