http://qs1969.pair.com?node_id=689020

steph_bow has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

I would like to sort fileswhose name are for examples : M3_output_ZGZ22_02_20061022_duration_200mn_comptage_60.txt

I have built the following sub routine:

use strict; use File::Copy; sub files_sort { my $first_number; my $second_number; if ($a =~ /(\d+)_(\d+)_duration_(\w+)_comptage_(\d+).txt$/){ $first_number = $1; } if ($b =~ /(\d+)_(\d+)_duration_(\w+)_comptage_(\d+).txt$/){ $second_number = $1; } if ($1 < $2){ -1 } elsif($1 > $2){ 1 } else{ 0} } my @TXT = glob("*.txt"); @TXT = sort files_sort @TXT;

Is that OK ? Thanks

Update: thanks to pisni for correcting my mistake, I just want to order the list by the number 02, 04, 12, not the date (20061022).