Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (13)
As of 2014-12-26 17:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (174 votes), past polls