glob plainly emulates shell globbing, and does not work with regexen. You can either use File::Find (or its relatives File::Find::Rule and File::Finder) even if you do not need to recurse, or just opendir, readdir and grep on filenames yourself.
Or else, now that I think of it, shouldn't *_{process,read}[+_]* work? Well, not exactly, because it would give false positives if "+" were not the first one. Maybe it's enough for you, anyway...
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: Thats a simplification of the code, which works, I havent tested or run the code above. Its just for illustration here.Thanks for your suggestions. Unfortunately File::File etc wont work as we dont 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 [cpan://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 [doc://glob] whereas I often see people do unnecessary [doc://opendir]s and [doc://readdir]s, 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, [id://510594].
perlmonks.org content © perlmonks.org and bangers, blazar
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03