Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Using an array that contains wildcard characters for pattern matching.

by crashtest (Curate)
on Oct 28, 2014 at 01:25 UTC ( #1105228=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1105228]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2020-06-05 19:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (40 votes). Check out past polls.

    Notices?