in reply to Using an array that contains wildcard characters for pattern matching.
It would be helpful if you described how your program isn't working. I gave this a run on my machine and it seemed every file and directory was printed as a match. Is that what you're experiencing?
As far as insight, I think you'll find putting use strict; at the top of your script (and use warnings;) will help a lot. It reports:
Global symbol "$patterns" requires explicit package name ... line 57 Global symbol "$patterns" requires explicit package name ... line 62
The array @patterns is a separate variable from the scalar $patterns, which you're using in your "if" statement. You'll probably want something along the lines of:
if (grep { $path =~ qr/$_/ } @patterns) ...
Having said that, I see a second problem in the format of your search patterns. They aren't regular expressions, they're shell-like globs. For example, *\PL\* is not a valid regex; you'd want .*\PL\.*.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Using an array that contains wildcard characters for pattern matching.
by james28909 (Deacon) on Oct 28, 2014 at 01:47 UTC |