develooper Front page | perl.fwp | Postings from March 2002

Re: TPR1 post-mortem

Thread Previous | Thread Next
From:
Ronald J Kimball
Date:
March 8, 2002 06:42
Subject:
Re: TPR1 post-mortem
Message ID:
20020308094235.C1569816@linguist.thayer.dartmouth.edu
On Fri, Mar 08, 2002 at 12:04:15PM +0100, F.Xavier Noria wrote:
> On Fri, 08 Mar 2002 11:41:31 +0100
> cizaire_liste <cizaire_liste@yahoo.com> wrote:
> 
> : Can someone explains me why 
> : 
> : my $c = '($a="www")=~s{}{z}g;print "$a\n";die';
> : eval $c;
> : $^O=~s{.}{$c}ee;
> : 
> : output two lines that are different ?
> : ($^O is only used to have a not empty string)
> 
> I have not studied it carefully, but at first sight I see a possible
> gotcha, when the pattern is {} s uses the last successful pattern that
> matched (this is surely imprecise or false, I have not the Camel book
> here), just to throw an idea.

Nice work, that is the correct explanation.

The first time $c is evaled in the code snippet, there is no previous
successfully matched pattern, so s{}{z}g matches the null string at every
position in $a.  When $c is evaled inside s{.}{$c}ee, the pattern /./ was
just successfully matched, so s{}{z}g matches /./.

This shows the same behavior:

($a="www")=~s{}{z}g;
print "$a\n";

$a =~ /./;

($a="www")=~s{}{z}g;
print "$a\n";

Ronald

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