Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Captured single quote results in captured phantom quote

by Ach (Initiate)
on Aug 24, 2016 at 21:21 UTC ( #1170343=perlquestion: print w/replies, xml ) Need Help??

Ach has asked for the wisdom of the Perl Monks concerning the following question:

This appears to be a bug in v5.22.2 built for cygwin-thread-multi:

DB<1> $line = "\"quoted-text\" \cM\cJ" DB<2> x $line 0 "\"quoted-text\" \cM\cJ"

My original regex:

DB<3> x $line =~ m/^(\s*)((?'quote'"?)[^\s"]*\g{quote})\s+(\[[^\]]*\ +]|)\s*$/ 0 '' 1 '"quoted-text"' 2 '"' 3 ''

Remove backreference:

DB<4> x $line =~ m/^(\s*)((?'quote'"?)[^\s"]*")\s+(\[[^\]]*\]|)\s*$/ 0 '' 1 '"quoted-text"' 2 '"' 3 ''

Replaced named with unnamed group:

DB<5> x $line =~ m/^(\s*)(("?)[^\s"]*")\s+(\[[^\]]*\]|)\s*$/ 0 '' 1 '"quoted-text"' 2 '"' 3 ''

Replace unnamed group with internals of group:

DB<6> x $line =~ m/^(\s*)("?[^\s"]*")\s+(\[[^\]]*\]|)\s*$/ 0 '' 1 '"quoted-text"' 2 '' 3 ''

Needless to say, the commands 2-5 resulted in the wrong result for array element 2.

Has this been discovered and fixed yet?

 

Ach

Replies are listed 'Best First'.
Re: Captured single quote results in captured phantom quote
by AnomalousMonk (Bishop) on Aug 24, 2016 at 22:45 UTC

    NOTE: The original OP had
        DB<1> $line = "\"quoted text\" \cM\cJ"
    (which does not match at all) in place of the current
        DB<1> $line = "\"quoted-text\" \cM\cJ"
    (which matches as I would expect). Please be aware that silent updates like this can be very annoying. Please see How do I change/delete my post? for site etiquette and protocol regarding editing posts.

    ... the wrong result for array element 2.

    I'm not sure what you mean by this: can you please clarify? Old and new strings match (update: and capture) as I expect. (Update: But I can only run Perl version 5.14.4 at most. (Further Update: I get the same results from my script running under 5.10.1, both Strawberry.))

    Output:


    Give a man a fish:  <%-{-{-{-<

      Getting exactly the same output with 5.20.1 on Linux.

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      Sorry, I realized almost immediately that the space would have broken the examples, so I changed it. I'll keep the etiquette in mind next time.
        Sorry, ... I'll keep the etiquette in mind next time.

        Ok, great, no problem! But I still don't understand your difficulty as expressed in the OP. Does it have anything to do with the point made in sn1987a's reply?


        Give a man a fish:  <%-{-{-{-<

Re: Captured single quote results in captured phantom quote
by sn1987a (Chaplain) on Aug 25, 2016 at 12:32 UTC

    The observed behavior is correct. The named captures do not prevent the contents from saved to the numbered capture variables. So in your first three regexs, element 1 gets the entire quoted string and element 2 gets the first quote.

      Oh yeah, that's right. Named capture groups doesn't affect the array of captured groups.

      Thanks

Re: Captured single quote results in captured phantom quote
by Ach (Initiate) on Aug 24, 2016 at 22:07 UTC

    This appears to be still happening in Strawberry Perl: v5.24.0 built for MSWin32-x64-multi-thread

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2019-10-18 21:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?