[tpm] Another Regex question

Fulko Hew fulko.hew at gmail.com
Tue Oct 23 09:04:43 PDT 2012


On Tue, Oct 23, 2012 at 11:41 AM, Antonio Sun <antoniosun at lavabit.com> wrote:
>
>>        if (( -f $file) && ( $file =~ /\.(inp|pd2)$/ ))
>
> without much formal requirement definition, try to start with this
>
>         if (( -f $file) && ( $file =~ /^\w+-\w+\.(inp|pd2)$/ ))


That just makes the regex even MORE specific, the question is
why doesn't the original test work?

I tried:

perl -e '$file = "SomeFIle-Name.r2.pd2"; if ($file =~ /\.(inp|pd2)$/)
{ print "found\n"; } else { print "not found\n"}'

and it worked... just like you'd expect!

So I suspect that your being caught on the '-f $file' check.
I didn't look into it, but... are you being caught by the (potential?) problem
that you are getting just a filename, and not a filespec provided to
the '-f' test,
and hence the file isn't found ?

>
> On Tue, Oct 23, 2012 at 10:57 AM, Chris Jones <cj at enersave.ca> wrote:
>>
>> Thank you so much for all your help!
>> I must make a donation to something in compensation for making my work
>> life more productive!
>>
>> I have a bunch of files to delete in sub-directories.
>>
>> I only want to keep files with the following pattern:
>> SomeFIle-Name.inp
>> SomeFIle-Name.pd2
>>
>> Any other files should be deleted.  Unfortunately my simple search did not
>> separate files such as:
>> SomeFIle-Name.r2.inp
>> SomeFIle-Name.r2.pd2
>> SimFile-Name.r2 - Baseline Design.inp
>>
>> #!/usr/local/bin/perl
>> use strict;
>> use File::Find;
>>
>> $\="\n";
>> $,="\n";
>>
>> my $start=("./");
>>
>> finddepth (\&wanted, $start);
>> sub wanted {
>>         my $file = $_;
>>         #mod, eux, cfg test for each one
>>         if (( -f $file) && ( $file =~ /\.(inp|pd2)$/ ))
>>         {
>>                 print "File $file, keep\n";
>>                 }
>>                 else
>>                 {
>>                         print "File $file, delete\n";
>>                 }
>> }
>>
>>
>>
>>
>>
>>
>>
>> >>
>> Christopher Jones, P.Eng.
>> Suite 1801, 1 Yonge Street
>> Toronto, ON M5E1W7
>> Tel. 416-203-7465
>> Fax. 416-946-1005
>> email cj at enersave.ca
>>
>> _______________________________________________
>> toronto-pm mailing list
>> toronto-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/toronto-pm
>
>
>
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm
>


More information about the toronto-pm mailing list