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 <[EMAIL PROTECTED]> 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

Reply via email to