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

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

Thread Next
From:
Enache Adrian
Date:
February 21, 2003 07:50
Subject:
[perl #20682] [fix] @- array not visible in s///
Message ID:
20030221155014.GB793@ratsnest.hole
$ perl -le '$_="123"; s/(1)(2)(3)/$#-/; print'

It should print 3.

Patch:
----------------------------------------------------------------------
--- /arc/perl-current/op.c	2003-02-16 17:05:00.000000000 +0200
+++ perl-current/op.c	2003-02-21 05:01:04.000000000 +0200
@@ -2634,7 +2634,7 @@ Perl_pmruntime(pTHX_ OP *o, OP *expr, OP
 		    if (curop->op_type == OP_GV) {
 			GV *gv = cGVOPx_gv(curop);
 			repl_has_vars = 1;
-			if (strchr("&`'123456789+", *GvENAME(gv)))
+			if (strchr("&`'123456789+-", *GvENAME(gv)))
 			    break;
 		    }
 		    else if (curop->op_type == OP_RV2CV)
----------------------------------------------------------------------
#!/usr/bin/perl
require "test.pl";
{
    $_= "123"; s/(1)(2)(3)/$#-/;
    is ($_,$#-,"#20682 @- not visible in s///")
}
__END__
----------------------------------------------------------------------

When the replacement body has no side effects, the code in
Perl_pmruntime() (op.c:2563) doesn't built a substcont block;
that's why, for instance, in

$ perl -e 's/a/$a[warn]/'

the warn will be executed, even if the substitution failed.
The builtins that do i/o have of course side effects: flagging
them with 'd' in opcode.pl could be a solution. That will be
only marginally useful, though.

The same happens for tied variables:
$ perl -e '{package P;sub TIESCALAR{bless{}};sub FETCH{warn}} \
	tie $a,P ; s/a/s$a/'

notice that FETCH may have inpredictable side-effects, too.

The /e flag seems to be the only solution in this case.

Regards

Adi


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