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

Re^2: strange usage of s///

by davido (Archbishop)
on Sep 03, 2013 at 17:26 UTC ( #1052150=note: print w/ replies, xml ) Need Help??


in reply to Re: strange usage of s///
in thread strange usage of s/// [solved: Perl 5.14 and 5.16 bug]

Neigher \K nor /r existed in Perl 5.6.x, which is the latest version of the regexp syntax that YAPE::Regex::Explain supports. (This is documented, and would have been pretty easy to test.)

perl -MYAPE::Regex::Explain -E 'say YAPE::Regex::Explain->new(q/@{[s". +."."gr]}\K$"/)->explain'

...produces the following output (assuming a Perl that is recent enough to understand \K and /r):

The regular expression: (?-imsx:@{[s".."."gr]}\K$") matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- @{ '@{' ---------------------------------------------------------------------- [s".."."gr] any character of: 's', '"', '.', '.', '"', '.', '"', 'g', 'r' ---------------------------------------------------------------------- } '}' ---------------------------------------------------------------------- \K 'K' ---------------------------------------------------------------------- $ before an optional \n, and the end of the string ---------------------------------------------------------------------- " '"' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------

...which obviously is totally wrong. It completely misses that @{[.....]} interpolates code into a string (it instead thinks it's looking at a character class), it mistakes \K for literal "K", and mistakes $" for an end of line/string metacharacter, followed by a literal ", when it really should see the Perl special variable. Add to that the fact that it couldn't possibly understand the /r semantics, and the fact that we're using the regexp engine re-entrantly (which I don't think used to be possible), and it's a hopeless case for poor old YAPE::Regex::Explain.

I too am confused by why he demonstrated /@{[s".."."gr]}\K$"//; I don't see it mentioned among the submissions I viewed, and I don't see any mechanism for it actually doing what it's supposed to. It certainly doesn't match the code in the link provided.


Dave


Comment on Re^2: strange usage of s///
Select or Download Code
Re^3: strange usage of s///
by smls (Friar) on Sep 03, 2013 at 17:36 UTC
    Neigher \K nor /r existed in Perl 5.6.x, which is the latest version of the regexp syntax that YAPE::Regex::Explain supports. (This is documented, and would have been pretty easy to test.)

    Yes, my bad.

    I made up for it by providing a proper, detailed answer below... :)

Re^3: strange usage of s///
by brx (Pilgrim) on Sep 03, 2013 at 20:16 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2014-09-22 16:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (198 votes), past polls