Stephen Turner wrote in perl.fwp:
> 
> 2) This works:
> 
> sub _{local$a;print$_=pop,$/;/..(?{$a.=$&%9||9*!!-$&})\b/&&_($a)}_ pop
> 
> But with "my" instead of "local" it doesn't. I don't understand this. (I was
> trying to shorten $a='').

This is probably due to the fact that the regexp is compiled only once,
and if you use "my $a", the $a in the regexp code block refers to the
lexical $a corresponding to the 1st call to _().

More concisely, the following :
    sub f { my $x = 1; /(?{print $x++})/; } f; f; f;
prints "123".
This is a bug, and I can reproduce it with perl 5.7.3.

Using eval around the regexp (the string version of eval, to force
recompilation) solves the problem. But you'll lose at least 6 strokes...

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/ / http://lyon.pm.org/
There's always something that's known to be painfully broken, for some
definitions of pain and broken. -- Jarkko Hietaniemi

Reply via email to