in reply to Re: Using an array that contains wildcard characters for pattern matching.
in thread Using an array that contains wildcard characters for pattern matching.

this works great until i add anything like \turkish or \localization and i think it has to do with \t ect, but it can be easily rectified i believe. thanks for the great example as well :)
  • Comment on Re^2: Using an array that contains wildcard characters for pattern matching.

Replies are listed 'Best First'.
Re^3: Using an array that contains wildcard characters for pattern matching.
by james28909 (Deacon) on Oct 28, 2014 at 17:29 UTC
    for further reference i will attach these pattern files and a slightly modified version of my code using your regex.
    use strict; use warnings; use diagnostics; use File::Slurp; use File::Copy::Recursive qw(rcopy fcopy); use File::Basename; my @dirs; my @patterns; my $dir1 = $ARGV[0]; get_filelist($dir1); get_patterns(); move_files(); mkdir('./ripped'); sub get_filelist { 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 ) { get_filelist("$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>){ #$_ =~s/[*]/.*/g; #$_ =~s/\\/\//g; $_ =~ s[\\/][\\\\/]g; $_ =~ s/\\/\\\//g; $_ =~ s/\./\\./g; $_ =~ s/^\*//; $_ .= '$' if $_ !~ s/\*$//; $_ =~ s/\*/.*/g; $_ =~ s/\?/./g; chomp $_; $_ = $_.'|'; push @patterns, $_; } close($file); } } sub move_files{ my $regex = join('', @patterns); print $regex; for my $element(@dirs){ if ($element =~ $regex){ print "Found $element\n"; # rcopy($element, "ripped/$element"); } } }
    here is the compelet pattern set. pattern files I thought i had it working, but it was still missing alot of files, and still copying alot of files it wasnt suppose to and i am unsure on which way to go with it now. i have tried replacing '*' with '.*' and '?' with '.', but it is still failing because it is replacing all instances of * and ?

    i have also found Regexp::Wildcards i will see how that works as well