Thanks for your suggestions. Unfortunately File::File etc won’t work as we don’t want to change several 1,000 file specs ( sorry if some of the restriction seem arbitrary, but there are good reasons for them)
In the end we decided to use the file spec to pull back a super set of what we wanted. We then converted any '*' into '(.*?)' and did a regex. If $1 contains a '+' then we exclude the file e.g.
my $spec = ‘*_{process,read}_*’;
my $reg = $spec;
$reg =~ s/\*/(.*?)/g;
my @use;
for my $file ( glob $spec ) {
$file = m/$reg/;
push @use, $file unless $1 =~ /\+/;
}
Note: That’s a simplification of the code, which works, I haven’t tested or run the code above. It’s just for illustration here.
I suppose in the end it was a PERL question after all.
| [reply] [d/l] |
Thanks for your suggestions. Unfortunately File::File etc won’t work as we don’t want to change several 1,000 file specs ( sorry if some of the restriction seem arbitrary, but there are good reasons for them)
To be fair I don't understand your concerns since I don't have the slightest idea about what you mean with "to change several 1,000 file specs". I suspect that you, in turn, did misunderstood the suggestion about File::Find.
my $spec = ‘*_{process,read}_*’;
Please use real single quotes: what are you using as an editor?!?
my @use;
for my $file ( glob $spec ) {
$file = m/$reg/;
push @use, $file unless $1 =~ /\+/;
}
This won't work, since since {process,read} does not do what you seem to think it does, in a regex. You probably want
my @use=grep !/[^+]*?_(?:process|read)_/, glob $spec;
But then you should be aware that you're duplicating your efforts, performing two very similar pattern matches one after the other. Although I'm a big advocate of glob whereas I often see people do unnecessary opendirs and readdirs, in this case I feel like suggesting you to follow that path...
I suppose in the end it was a PERL question after all.
No, it was not a "PERL" question, since there's not such a thing. Check
perldoc -q 'difference between "perl" and "Perl"'
and while you're there, PERL as shibboleth and the Perl community. | [reply] [d/l] [select] |