develooper Front page | perl.perl5.porters | Postings from October 2012

[perl #33820] Regex bug: auto-reference to a capture used in a conditional expression

From:
Karl Williamson via RT
Date:
October 22, 2012 18:36
Subject:
[perl #33820] Regex bug: auto-reference to a capture used in a conditional expression
Message ID:
rt-3.6.HEAD-11172-1350956169-899.33820-15-0@perl.org
On Fri Jan 20 09:21:23 2012, rjk@tamias.net wrote:
> On Thu, Jan 19, 2012 at 06:54:34PM -0800, James E Keenan via RT wrote:
> > On Mon Jan 17 08:49:39 2005, philippe.verdret@xps-pro.com wrote:
> > > In a capture a reference to this capture is perfectly possible:
> > > 
> > >   "baaa" =~ (\1|a)+
> > > 
> > > the result of this match is b<aaa>.
> 
> > #####
> > $ perl -e '"baaa" =~ m/(\1|a)+/;print "$1\n"'
> > a
> > $ perl -e '"baaa" =~ m/((?(1)a|a))+/;print "$1\n"'
> > a
> > $ perl -e '"baaa" =~ m/"baaa" =~ ((?(1)a|b))+/;print "$1\n"'
> > 
> > $ perl -e '"baaa" =~ m/"baaa" =~ ((?(1)a|b(?{})))+/;print "$1\n"'
> > 
> > #####
> > So either I'm misinterpreting the OP, or his original premise was
> > incorrect, or Perl has changed since this was posted seven years ago.
> 
> I think you are misinterpreting the OP.  You should be printing $&,
not $1.
> (In addition to the copy-paste errors in the last two tries.)
> 
> Ronald
> 

And for those of you following along at home, if you do this, you get
the results that the OP said you would
-- 
Karl Williamson

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=33820



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About