in reply to How do I sort by certain parts of a filename?

Don't know if this is the most efficient:

my @files = qw{ Date12_type.asp Date1_type.asp Date7_type.asp Date4_ty +pe.asp }; my @sorted_files = map { join '', @{$_} } sort { $a->[1] <=> $b->[1] } map { [(/([^\d]+)(\d+)(.*)/)] } @files; $,="\n"; print @sorted_files;

The above code prints:

Date1_type.asp Date4_type.asp Date7_type.asp Date12_type.asp

I was just guessing as to the file names, as the example you provided was unclear to me. The actual regular expression may need to be adjusted. Also, the sort has been done numerically, which is what I guessed you wanted.

If this doesn't get it done, post some filename samples along with sample sorted output.

Cheers,
Ovid

Update: I think Masem gave a clearer (and better) answer. Vote for him.

Update 2: cLive ;-) pointed out that I probably misread your post and, as a result, my sort won't work. Again, post some filenames and the expected sort order, and we can better answer this.

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.