Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: You don't always have to use regexes

by ysth (Canon)
on Feb 24, 2005 at 19:34 UTC ( [id://434210]=note: print w/replies, xml ) Need Help??


in reply to You don't always have to use regexes

A proper translation of if ( $value =~ /^true$/i ) would be:
if ( lc $value eq "true" || lc $value eq "true\n" )
(except that the former potentially sets $&, $`, and $' and the last-successful-regex).

Replies are listed 'Best First'.
Re^2: You don't always have to use regexes
by petdance (Parson) on Feb 25, 2005 at 03:02 UTC
    Yes, but that check for "\n" is really irrelevant. It's required to be functionally identically, but not semantically.

    Semantics are the real issue here. The regex is saying "Do you have a string that matches the beginning of the string, then t, r, u, e and then the end of the string", and the compare is saying "Is the string the word 'true'?"

    "Is this the word I want" is the real intent.

    xoxo,
    Andy

      My point was that that is not what the regex is saying. Just my own personal bonnet-bee, but people misinterpret $ way too often, and I feel it deserves publicity whenever it comes up.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-19 02:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found