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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Come now. You can't use the documentation which is written after the code has been written as a reason why they code works (or doesn't work) a certain way. The documentation describes behavior -- it is not a justification as to 'why' the code works that way -- or why the 'g' switch was *deprecated* (meaning, that it used to be legal code).

It implies that the decision was somewhat arbitrary and that it could still work the old way, except someone chose to add another *wart* to perl and create another exception -- that RE's work a certain way in some places, but another way when described by 'qr'.

As for 'x' working -- i'd call this broken. Why not use the example I provided that shows the broken behavior rather than coming up with some different example where you could make it work?

I.e.:

perl -we'use strict;use P; my $re = qr{ (?x) (\w+) }; my $dat = "Just another cats meow"; my @matches = $dat =~ $re; P "#matches=%s, matches=%s", scalar(@matches), \@matches; exit scalar(@matches);' #matches=1, matches=["another"]

the above doesn't work. It doesn't return the 1st match from the text line. As opposed to moving the (?x) to the end of the qr statement:

perl -we'use strict;use P; my $re = qr{ (\w+) }x; my $dat = "Just another cats meow"; my @matches = $dat =~ $re; P "#matches=%s, matches=%s", scalar(@matches), \@matches; exit scalar(@matches);' #matches=1, matches=["Just"]

In the case where I am not using 'g', One would expect the re to match and return the 1st word in the list. With (?x), it doesn't return the 1st word, but returns the 2nd, vs. with 'x' as a suffix, it behaves as expected and only returns the 1st matching word.

Then you claim the status quo makes sense, when the perl mastery book clearly shows that 'qr' can stand as an RE by itself without 'm' or 's' -- AND it is more efficient when it is used that way. Except it has been crippled by differences in how 'RE's work in 'qr' vs. ones that are "requoted", re-interpolated, and re-compiled in 'm' & 's'. Why is there a difference when 'qr' can be used "standalone"? "qr" wasn't meant to replace 's', but it was meant to replace or be equivalent to 'm'.

Did you see the 3 ways Mastering perl uses 'qr'. The first way, where it is interpolated, seems to have little benefit over using q(string). then interpolating the string into the m{} statement. But if you can use 'qr' w/o the m{}, you only do the RE-compile once when you use 'qr' -- which can be used to match things directly in "=~" statements -- just like m{} statements are used.

So again, I ask 'why' the artificial constraint when, from the deprecation warning, it seems apparent, that it used to work.


In reply to Re^2: 'g' flag w/'qr' by perl-diddler
in thread 'g' flag w/'qr' by perl-diddler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-03-29 04:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found