Sortin my Array in Numerical Order

Ken Elliott's picture

They have: 358 posts

Joined: Jun 1999

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!

They have: 447 posts

Joined: Oct 1999

@array=sort(@array);

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.

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.