Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Possible Match Problem

by ww (Bishop)
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"; }
Comment on Re: Possible Match Problem
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2016-04-30 08:35 GMT
Find Nodes?
    Voting Booth?
    :nehw tseb si esrever ni gnitirW

    Results (441 votes). Check out past polls.