Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
"be consistent"
 
PerlMonks  

Re^2: Problems with a regex?

by hbm (Hermit)
on Aug 14, 2012 at 15:59 UTC ( #987391=note: print w/ replies, xml ) Need Help??


in reply to Re: Problems with a regex?
in thread Problems with a regex?

To /^\Q$stack\E$/ (emphasis on the \E).

And to the OP, note that your first RE can be simplified:

#if ($line =~ m/set\sservice\s(\".+\").?/) { if ($line =~ m/set\sservice\s(".+")/) {

No need to escape quotes; nor to match beyond what you are interested in. (I often see REs with a useless .* at the end.)


Comment on Re^2: Problems with a regex?
Select or Download Code
Re^3: Problems with a regex?
by BrowserUk (Pope) on Aug 14, 2012 at 16:05 UTC
    To /^\Q$stack\E$/ (emphasis on the \E).

    Why? If the \E comes at the end of the regex it is completely redundant. A pointless, useless addition.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      I would think so too, reading the docs. But with /^\Q$stack\E$/, I get:

      Service name: "MY NEW SERVICE (TMP)" Popping stack: . Adding to stack: "MY NEW SERVICE (TMP)" Service name: "MY NEW SERVICE (TMP)" It's on stack, keep compiling

      And with /^\Q$stack$/, I get:

      Service name: "MY NEW SERVICE (TMP)" Popping stack: . Adding to stack: "MY NEW SERVICE (TMP)" Service name: "MY NEW SERVICE (TMP)" Popping stack: "MY NEW SERVICE (TMP)". Adding to stack: "MY NEW SERVIC +E (TMP)"

      More simply:

      $ perl -e "$x=$_='()';print/^\Q$x\E$/?YES:NO" YES $ perl -e "$x=$_='()';print/^\Q$x$/?YES:NO" NO

        Mea culpa! You're right. Escaping the $ makes the difference.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (19)
As of 2014-04-16 13:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (427 votes), past polls