Sorting numbers in an array

Scott Elcomb Scott.Elcomb-iRg7kjdsKiH3fQ9qLvQP4Q at public.gmane.org
Wed Aug 18 03:06:36 UTC 2004


On Tue, 2004-08-17 at 22:51, Madison Kelly wrote:
> Hi all,
> 
>    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)?
> 
>    Thanks!

How many dimensions are in the array?

Single-dimensional arrays can be done quickly with sort (works with
floats as well)

Eg.

my @ints = qw(3 8 4 7 5 3 5 1);
my @sorted_ints = sort(@ints);

foreach my $num (@sorted_ints) {
        print "$num\n";
}

Hope it helps.

- Scott.

-- 
https://sourceforge.net/projects/avalonweb/

PGP Public Key:
1024D/98125E76 2004-03-21 Scott Elcomb (dL33T) <Scott.Elcomb-iRg7kjdsKiH3fQ9qLvQP4Q at public.gmane.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://gtalug.org/pipermail/legacy/attachments/20040817/2613056a/attachment.sig>


More information about the Legacy mailing list