FAQ
# New Ticket Created by Nathan Trapuzzano
# Please include the string: [perl #121299]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/Ticket/Display.html?id=121299 >


This bug report corresponds to the discussion at:
http://www.nntp.perl.org/group/perl.perl5.porters/2014/02/msg212894.html

Perl (5.16.3 and 5.18.1 at least) doesn't always handle backreferences
inside subpattern calls correctly. For example,

   say 'fofof' =~ /(.)((o)\1)(?2)/ ? 'true' : 'false'
   ==> true

   say 'fffffff' =~ /(.)(?2)((\1)(?4)(\1))/ ? 'true' : 'false'
   ==> false

   say 'foffoff' =~ /(.)(?2)((.)(?4)(\1))/ ? 'true' : 'false'
   ==> false

"use re 'debug'" shows that the second and third examples fail at the
first '\1' encounter, as though the first capture were being reset upon
entering the sub call. However, in the first example, the capture is
cearly retained in the '(?2)' call.

A similar (same?) problem occurs with forward or self-referential
backreferences:

   print 'abcb' =~ /^(.\2?)(.)(?1)$/ ? "true\n" : "false\n"
   => false

   print 'abcb' =~ /^(.(?{ printf "%d, $2\n", pos()})\2?)(.)(?1)$/ ? "true\n" : "false\n"
   => 1,
   => 3, b
   => false

   print 'aba' =~ /^(.\1?)(?1)$/ ? "true\n" : "false\n"
   => false

   print 'aba' =~ /^(.(?{printf "%d, $1\n", pos()})\1?)(?1)$/ ? "true\n" : "false\n"
   => 1,
   => 2, a
   => false

In second example immediately above, the diagnostics say that we're
about to try to match 'b' at pos 3, which should succeed. Ditto for the
fourth example.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl5-porters @
categoriesperl
postedFeb 22, '14 at 1:56a
activeFeb 22, '14 at 1:56a
posts1
users1
websiteperl.org

1 user in discussion

Nathan Trapuzzano: 1 post

People

Translate

site design / logo © 2021 Grokbase