http://www.perlmonks.org?node_id=1105228


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
    yes it is copying every file, which is NOT what i want it to do ofcourse lol. sorry for leaving that out. and looks like i will need to redo my pattern files. but i want the patterns to help filter out the files i do not want, and just move them to a different directory.

    i now see what you mean about the shell patterns. here is a webpage i just found that describes the problem and a solution. http://bioinfo2.ugr.es/documentation/Perl_Cookbook/ch06_10.htm