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).
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: sorting files
by reasonablekeith (Deacon) on May 29, 2008 at 14:57 UTC | |
Re: sorting files
by toolic (Bishop) on May 29, 2008 at 15:01 UTC | |
by GrandFather (Saint) on May 29, 2008 at 20:04 UTC | |
Re: sorting files
by psini (Deacon) on May 29, 2008 at 14:37 UTC | |
Re: sorting files
by graff (Chancellor) on May 30, 2008 at 02:22 UTC | |
Re: sorting files
by poolpi (Hermit) on May 30, 2008 at 13:06 UTC |
Back to
Seekers of Perl Wisdom