in reply to Re^3: Compare two arrays
in thread Compare two arrays

I tested like this:
... for my $filename (@file) { #next unless $filename =~ /^\d+/; #if(grep { $seen{$_} =~ $filename} keys %seen) { # Failed #if(grep { $filename =~ $seen{$_} } keys %seen) { # Failed if(grep { $filename =~ /\Q$_/ } keys %seen) { print " YES - $filename\n"; } else { print " NO - $filename\n"; } }
Why would it only work using "quotemeta"? I even removed the
"next unless $filename =~ /^\d+/;

Thanks for you time!

Replies are listed 'Best First'.
Re^5: Compare two arrays
by Eily (Monsignor) on Oct 01, 2014 at 22:26 UTC

    quotemeta (the \Q in the regex) makes sure that perl tries to find the string exactly as it is in $filename. If you don't use it, it will "translate" any meta character into its regex meaning. In your case, it probably does the same though.