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

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 the radiator hisses contentedly...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2017-12-18 15:55 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (492 votes). Check out past polls.