Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Possible Match Problem

by ww (Archbishop)
on Jan 18, 2012 at 23:03 UTC ( #948644=note: print w/replies, xml ) Need Help??

in reply to Possible Match Problem

And, in some cases, you may want to use eq instead of relying on a regex.

In this case, I can't reproduce your success when using all lc letters in the $strings... which is what I was trying to do as Brother toolic posted the excellent explanation that metachars, such as parens, have to be escaped (see perlre for more). But note also, below, the use of the qr in creating $str1

#!/usr/bin/perl use strict; use warnings; # "use Diagnostics;" might help you, too. # 948631 my $str1 = qr/hi\(/; # Note use of qr here; see perldoc perlre or p +erlretut # Escaped paren; no more complaints from the r +egex engine my $str2 = "hi"; # All lc did NOT work until the paren was esca +ped if ($str2 =~ $str1) { print "Match: Yes\n"; } else { print "Match: No\n"; } say "Now, using 'eq'"; if ($str2 eq $str1) { print "Match: Yes\n"; } else { print "Match: No\n"; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://948644]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2017-04-24 06:39 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (435 votes). Check out past polls.