I am trying to find any non english files or folders and copy them to a different directory, which everythign is working great except the pattern match.

I have a directory of files and each file in this directory contain a pattern to match with, like this for example:
*\PL\* *\pl-*.fbrb *_pl-*.fbrb *\*_pl-00.fbrb *\pl-00.fbrb *\polish\* *\psarc\polish*.psarc *_POL.* *_POLISH.SUB *_POL_* *_po.xvag *_polish.* *.pl.* *_pl.psarc *_pl2.psarc *_pol.* *_por.*
I slurp this data into an array called @patterns. and then i recursively search the directory tree to find any files or folders that contain matches from the patterns in the @patterns array, which is not working. i am not sure about how to setup the regex match using wildcard chars from an array.
use File::Slurp; use File::Copy::Recursive qw(rmove); use File::Basename; my @patterns; my @dirs; my $searchDIR = $ARGV[0]; search_dirs($searchDIR); get_patterns(); move_files(); sub search_dirs{ my ($dir) = @_; my ($dh); if ( !opendir( $dh, $dir ) ) { return; } while ( my $file = readdir($dh) ) { next if ( -d $file ); my $path = "$dir/$file"; if ( -d $path ) { search_dirs("$path"); } else { push( @dirs, "$dir/$file" ); } } } sub get_patterns{ my @files = read_dir('patterns'); foreach my $element(@files){ open my $file, '<', "patterns/$element"; while(<$file>){ chomp $_; push @patterns, $_; } close($file); } } sub move_files{ for my $element(@dirs){ my($filename, $path, $ext) = fileparse($element, qr/\.[^.]*/); if ( $filename =~ $patterns ) { print "Found $element\n"; #rmove($element, "non-english/$path$filename$ext"); } if ( $path =~ $patterns ) { print "Found $path\n"; #rmove($path, "non-english/$path); } } }
if you need me to give more info please let me know. any insight would be appreciated, and thanks

In reply to Using an array that contains wildcard characters for pattern matching. by james28909

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.