Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^4: Compare two arrays

by Anonymous Monk
on Oct 01, 2014 at 17:57 UTC ( [id://1102567]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-03-29 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found