Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: qr// hidden risks

by perrin (Chancellor)
on Aug 10, 2003 at 16:22 UTC ( [id://282643]=note: print w/replies, xml ) Need Help??


in reply to Risks in the oblivious use of qr//

I don't mean to burst your bubble, but isn't this sort of obvious? The modifiers are an essential part of any regex. The qr// operator would be pretty lame if it didn't honor the modifiers that you compiled it with.

Replies are listed 'Best First'.
Re: Re: qr// hidden risks
by simonm (Vicar) on Aug 10, 2003 at 18:13 UTC
    The qr// operator would be pretty lame if it didn't honor the modifiers that you compiled it with.

    Yes, but that's a fair bit different than forcibly disabling the modifiers that you omitted...

    What's surprising is not that qr/perl/i produces (?i:perl), but that it produces (?i-xsm:perl), with the other modifiers explicitly disabled.

    That makes plenty of sense, but I'd never seen it explicitly documented before.

Re: Re: Risks in the oblivious use of qr//
by gmax (Abbot) on Aug 10, 2003 at 16:48 UTC
    but isn't this sort of obvious?

    Well, this is the whole point. It could not be ovbious for everyone. What is not clearly explained is that qr// will unset the modifiers that we haven't explicitly set.

    I didn't mean to rewrite the Bible :), but just to warn against something that may not be immediately perceived. The problem only exists when you embed a pre-compiled regex within a larger expression.

     _  _ _  _  
    (_|| | |(_|><
     _|   
    

      Well, people should read documentation. If you see "qr" and don't understand what it does, the first thing you should do is read the docs -- don't just assume you know how it works.

      From perldoc -f qr

             qr/STRING/
      
             qx/STRING/
      
             qw/STRING/
                     Generalized quotes.  See the Regexp Quote-Like
                     Operators entry in the perlop manpage.
      
      

      From perldoc perlop

             qr/STRING/imosx
                     This operators quotes--and compiles--its STRING as
                     a regular expression.  STRING is interpolated the
                     same way as PATTERN in `m/PATTERN/'.  If "'" is
                     used as the delimiter, no interpolation is done.
                     Returns a Perl value which may be used instead of
                     the corresponding `/STRING/imosx' expression.
      
      

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-25 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found