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

Re: [perl #129283] Compile-time check for $1, $2 om RHS of s///operator

Thread Previous | Thread Next
Lukas Mai
September 17, 2016 03:20
Re: [perl #129283] Compile-time check for $1, $2 om RHS of s///operator
Message ID:
Am 16.09.2016 um 23:36 schrieb Abigail:
> On Fri, Sep 16, 2016 at 04:15:13AM -0700, Ed Avis wrote:
>> # New Ticket Created by  "Ed Avis"
>> # Please include the string:  [perl #129283]
>> # in the subject line of all future correspondence about this issue.
>> # <URL: >
>> Currently this gives a run-time warning, but no compile-time error:
>>     use 5.022;
>>     $_ = 'abc';
>>     s/(a)/x$1$2/;
>>     say;
>> If the regexp on the LHS of s/// is known at compile time, then the
>> number of capturing groups it contains is known.  Under 'use strict',
>> a mention in the RHS of a capture variable which doesn't have a
>> corresponding capturing group (like $2 in the above example)
>> should give a compile-time error.
> "use strict" never promotes a 'Use of uninitialized value' to an
> error. I don't think perl being consistent when it comes to s///
> is a bug.

I agree.

It's not that $2 doesn't exist there; it just contains undef. 'strict' 
seems the wrong place for this check.

I would like to see it as a warning, but I don't know how hard it would 
be to implement (e.g. you'd have to check for embedded regex matches 
that could reset capture variables).

Lukas Mai <>

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About