develooper Front page | perl.perl5.porters | Postings from March 2003

Re: [perl #20682] [fix] @- array not visible in s///

Thread Previous | Thread Next
From:
Enache Adrian
Date:
March 1, 2003 20:05
Subject:
Re: [perl #20682] [fix] @- array not visible in s///
Message ID:
20030302040522.GB4905@ratsnest.hole
On Tue, Feb 25, 2003 at 03:20:46PM +0000, hv@crypt.org wrote:
> Also added the $^N, $^R extension as #18777; additional tests for these
> in t/op/subst.t would be appreciated.

Simple test for ^N:
---------------------------------------------------------------------------
--- /arc/perl-current/t/op/subst.t	2003-02-25 17:15:16.000000000 +0200
+++ subst.t	2003-02-26 00:47:13.000000000 +0200
@@ -7,7 +7,7 @@ BEGIN {
 }
 
 require './test.pl';
-plan( tests => 128 );
+plan( tests => 129 );
 
 $x = 'foo';
 $_ = "x";
@@ -527,3 +527,7 @@ $_ = "123";
 s/(1)(2)(3)/$#- (@-)/;
 is($_, "3 (0 0 1 2)", '#20682 @- not visible in replacement');
 
+# [perl #20682] $^N not visible in replacement
+$_ = "abc";
+/(a)/; s/(b)|(c)/-$^N/g;
+is($_,'a-b-c','#20682 $^N not visible in replacement');
---------------------------------------------------------------------------

The \022 (^R) seems not to be really needed. Notice however that it
(slightly) helps somehow by breaking the loop at the first $^R
- instead of continuing to walk through all the OPs in the replacement
( see op.c:2628 ).

Maybe change the loop there to do the same for all variables ?
( found a $var in the replacement && the pattern contains evals
  => break the loop ).
The improvement will be however very slight, since Perl_pmruntime isn't
usually called that many times.

Regards
Adi

Thread Previous | 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