in reply to RE: RE: extracting values from sort
in thread extracting values from sort
"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#!/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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE(4): extracting values from sort
by agoth (Chaplain) on Oct 04, 2000 at 15:51 UTC |