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

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

Thread Previous | Thread Next
From:
perl5-porters
Date:
February 21, 2003 13:44
Subject:
Re: [perl #20682] [fix] @- array not visible in s///
Message ID:
b366js$693$1@post.home.lunix
In article <20030221155014.GB793@ratsnest.hole>,
	Enache Adrian <enache@rdslink.ro> writes:
> $ 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;

mm, shouldn't ^R and ^N be in that list too then ?

>  		    }
>  		    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.
> 

A better side-effect detector seems better though. I must admit i've never
been bitten by it yet, but I sometimes do things like:
$a[$b{$c} || die "Oops ! no $c in hash"] so I suppose id'd better not 
combine that to s/.../$a[$b{$c} || die]/

Personally I'm not a fan of optimizations that are sometimes plain
incorrect. But flagging side-effect operators  operators and ignoring
overload and tie fetch seems an acceptable compromise.

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