chen li wrote:
Hi folks,
I have a folder containing a child folder and other
files. I want to print out the BMDC4-2.001 to
BMDC4-2.024 only and the file format is (string/number
or mix).number. Which regular expression is used to do
the job?
Thanks,
Li
########contents in the folder
folderx
Analysis-1.wsp
BMDC4-2.001
BMDC4-2.002
...
BMDC4-2.023
BMDC4-2.024
regexes can only match character patterns and can't make decisions based on the
numerical value of part of a string. Split the filenames into a name part and a
suffix part using a regex and compare them with the normal Perl operators.
HTH,
Rob
foreach (@folder) {
my ($name, $suffx) = /(.*)\.(.*)/;
next unless $name eq 'BMDC4-2';
next if $suffx =~ /\D/;
next unless $suffx >= 1 and $suffx <= 24;
print "$_\n";
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>