Sorting numbers in an array
Andy Jack
f.e.jack-bJEeYj9oJeDQT0dZR+AlfA at public.gmane.org
Wed Aug 18 03:10:24 UTC 2004
On Tue, Aug 17, 2004 at 10:51:17PM -0400, Madison Kelly wrote:
> I have an array of interger values in perl (i386 Linux 2.6 - FC2). Is
> there an easy way that anyone knows to pull those values out from
> smallest value to largest (or vice versa)?
Stolen from the Perl Cookbook (Recipe 4.14):
@sorted = sort { $a <=> $b } @unsorted;
Swap $a and $b if you want largest to smallest.
Cheers,
Andy
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list