Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Unexpected qr// behavior

by Paladin (Priest)
on Apr 20, 2004 at 14:53 UTC ( #346659=note: print w/replies, xml ) Need Help??


in reply to Unexpected qr// behavior

[~]$ perl -le '$re = qr/<!--.*?-->/; print $re;' (?-xism:<!--.*?-->)
As you can see, the qr// specificly turns off all options for the regex that you don't specify, which is why adding the /s afterwards doesn't make any difference.

As for whether this is a good thing or not, I can see arguments either way.

  • For: When you created the RE, you didn't say you wanted that option, so Perl makes sure that this particular part of the RE doesn't have that option. This is probably more usful when building a large RE up from smaller parts, and you want the different parts to act differently with regards to the various options.
  • Against: Like you saw, adding the /s didn't do what you meant. And Perl, after all, is usually very DWIMy.

Replies are listed 'Best First'.
Re(2): Unexpected qr// behavior
by bart (Canon) on Apr 20, 2004 at 16:01 UTC
    To make things even more clear (I hope), I'll just add that you can pass modifiers to qr, just like you can for normal regexes, like this:
    $re = qr/<!--.*?-->/s; print $re;
    which prints
    (?s-xim:<!--.*?-->)
    That is: /s enabled, and /x, /i and /m disabled.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://346659]
help
Chatterbox?
[SuicideJunkie]: Blergh. Trying to work into low level C code, stuff that would have been so easy with a regex.

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (13)
As of 2016-12-07 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (131 votes). Check out past polls.