Ok, I'm acting under the assumption that the leading "F" in your filenames is always going to be "F". If not, this might not do everything you need. Here goes:
use strict; use warnings; my @arr=( qw/ F1.jpg F10.jpg F11.jpg F12.jpg F1a.jpg F1b.jpg F2.jpg F3.jpg F4.jpg F5.jpg F6.jpg /); print "$_\n" for sort { my( $aye ) = $a =~ m/(\d+)/; my( $bee ) = $b =~ m/(\d+)/; $aye <=> $bee || $a cmp $b } @arr;
Here's how it works: Isolate the digits in each comparison, and do a numeric comparison just on the digits. If the numeric comparison equates to equality, the logical OR short circuit operator falls through to the string comparison. So you get numeric first, and asciibetical order second. I hope that's close to what you were looking for.
If the dataset is large and you intend on running the sort more than once, you might benefit from a Schwartzian Transform, but my guess is that you really don't need to be that concerned with efficiency.
For more info on sorting, read sort.
Update:I just noticed you want F1.jpg to appear after F1a.jpg. That's an unusual sort order. Are you sure you want that? Anyway, I've given at least enough of a building-block example upon which you can construct even more complex sort routines to satisfy whatever definition of "sorted" you wish to come up with. :) Enjoy!.
Dave
In reply to Re: Sort Array
by davido
in thread Sort Array
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |