develooper Front page | perl.perl5.porters | Postings from September 2011

[perl #96230] qr// reuses last successful pattern (like m//)

Thread Next
From:
Father Chrysostomos via RT
Date:
September 19, 2011 23:55
Subject:
[perl #96230] qr// reuses last successful pattern (like m//)
Message ID:
rt-3.6.HEAD-31297-1316501726-739.96230-15-0@perl.org
On Thu Aug 04 00:04:04 2011, rgs@consttype.org wrote:
> On 3 August 2011 23:54, l.mai@web.de <perlbug-followup@perl.org>
> wrote:
> >
> > % perl -wle '"a" =~ /[abc]/; my $re = qr//; $re eq "(?^:)" or die;
> $_ = "crab race"; s/$re/./g; print'
> > .r.. r..e
> >
> > What's going on here is that qr// takes the last successful regex
> and reuses
> > that pattern (/[abc]/), but stringification of the regex object
> still returns
> > "(?^:)". I'd say that's pretty bad because now we have qr objects
> whose
> > behavior is completely disconnected from their stringification. It
> also works
> > with interpolation - this bug bit me with qr/$foo/ where $foo
> happened to be
> > empty.

That surprised me, too.  One of my modules was buggy as a result, until
I changed qr)) to qr)(?:\)) :-)

> >
> > Yeah, so apart from this being bad I also think it's a bug because
> it doesn't
> > match the documentation in perlop.
> 
> My gut feeling is that this should be deprecated and then removed
> (that is, make qr// compile to an empty match.)

Jesse’s new 5.16 policy does not specify whether there should be a
deprecation warning if we change the behaviour.  Jesse, are you listening?

In a case like this, which of the following happens?
• use 5.014 gives no warning; use 5.016 gives new behaviour (like
unicode_strings)
• use 5.014 gives a deprecation warning; use 5.016 gives new behaviour
• use 5.014 gives no warning; use 5.016 gives deprecation warning and
old behaviour; use 5.018/20 gives new behaviour
• use 5.014/16 gives deprecation warning; use 5.018/20 gives new behaviour

I think I’m in favour of the first item.


Thread Next


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