Sortin my Array in Numerical Order
Hallo,
This is probably a simple question, but how do I sort my array into numerical order?
My array will contain file names (i.e. "1.txt", "2.txt", "12.txt", "32.txt", etc.)
How would I sort these into ascending order? 1 to 40?
Thanks for your infinite wisdom.
VulKen
I'm Too Phat
Pimpin like a pimp with an electrofied pimpin machine!
ROB posted this at 19:36 — 27th June 2000.
They have: 447 posts
Joined: Oct 1999
@array=sort(@array);
captain14 posted this at 20:44 — 27th June 2000.
They have: 20 posts
Joined: Feb 2000
I think that Howard's example sorts in ASCII order, not numerical.
I believe that,
@array=sort { $a<=>$b; } @array;
will work, but I have not tried it myself.
( PerlShell ) ( 3dStream )
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.