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

Re: [perl #26986] $& value does not properly propagate into replacement body of s///

Thread Previous | Thread Next
From:
Casey West
Date:
February 24, 2004 08:56
Subject:
Re: [perl #26986] $& value does not properly propagate into replacement body of s///
Message ID:
20040224165335.GF60929@geeknest.com
It was Monday, February 23, 2004 when perl-5.8.0@ton.iguana.be (via RT) took the soap box, saying:
: perl -wle '@F="A".."BZ"; $_="a"; s/./<$F[@a="b"..$&]>/; print; print"a=@a"'
: Argument "b" isn't numeric in range (or flop) at -e line 1.
: Use of uninitialized value in range (or flop) at -e line 1.
: Use of uninitialized value in range (or flop) at -e line 1.
: <B>
: a=0


If I add a /e modifier on the end of your s///, and fix up the
replacement section, I get the following:

perl -wle '@F="A".."BZ"; $_="a"; s/./join $F[@a="b"..$&], "<", ">"/e; print; print"a=@a"'
<Z>
a=b c d e f g h i j k l m n o p q r s t u v w x y z

: I expected $& to be "a", so @a should become (a b c ....z), so fetch 
: element 26 from @F, which should be "Z"

I think that I got what you expected. When you want to evaluate code
in a regular expression you must add the /e modifier. I think that
this is notabug. Am I missing something?

  Casey West

-- 
Good Idea: Taking a deep breath before jumping into a swimming pool.
Bad Idea:  Taking a deep breath after jumping into a swimming pool. 


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