Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

RegEx re-compilation

by habit_forming (Monk)
on Nov 14, 2003 at 15:58 UTC ( [id://307076]=perlquestion: print w/replies, xml ) Need Help??

habit_forming has asked for the wisdom of the Perl Monks concerning the following question:

Oh great and powerful Monks hallowed be thy code; see fit to explain to this humble servent the state of the /o switch when used on a RegEx that does not contain variables.

In other words... If a RegEx does not contain a variable is the /o implied? I looked in the camel book (pg 148) but I need a definitive Yes or No.

Thanks,
--habit

Replies are listed 'Best First'.
•Re: RegEx re-compilation
by merlyn (Sage) on Nov 14, 2003 at 16:19 UTC
    It's not implied. It's irrelevant. Since /o controls the treatment of variables, and there are no variables, it can neither be implied to be present or absent. The question has no merit.

    It's like saying "do I still get a free second helping of my entree with this coupon when all I'm having is dessert?" People turn their heads sideways when you say that. {grin}

    Is it helpful? No. Is it harmful? No, except that including that switch on a regex without variables might make me question the rest of your Perl understanding in a code review.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Is it helpful? No. Is it harmful? No, except that including that switch on a regex without variables might make me question the rest of your Perl understanding in a code review.

      I'd say that it can be harmful. Given the dynamic nature of code, an /o on a RE could cause some hard-to-find bugs if the RE were modified to use a variable but the /o not removed. In fact, I'd advocate that /o on a RE without variables should illicit a warning when -w is in effect.

      Sounds like it's maybe harmful to the guy that comes along three years later to maintain the code. In my experience, something that's not needed and can cause confusion is better left out.
      Thank you for the explanation. Apparently, I was very confused.

      --habit

        Funnily enough I came to the site to ask the same thing, and there was your question sitting at the top...

        IMHO RS was a bit harsh on you (and, by inference, me) - for a general user (i.e. one who hasn't had to write their own regex parser), it is by no means obvious that a regex is only 'compiled' when it contains variables.

        IMHO the problem is that 'compiled' is the wrong word in this context - compiling is something that is done to all code, not just variables. 'Expanded' might be a clearer term, but waddaiknow?

        Tom Melly, tom@tomandlu.co.uk
Re: RegEx re-compilation
by diotalevi (Canon) on Nov 14, 2003 at 17:16 UTC
    I wrote a longish thing about what exactly perl does with the /o flag at /o is dead, long live qr//!. Meryln's answer is about the same thing except succinct without all the the notes on the internals bits.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://307076]
Front-paged by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-24 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found