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.:
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:
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
|
|