Front page | perl.fwp |
Postings from March 2002
Re: TPR1 post-mortem
Thread Previous
|
Thread Next
From:
Rafael Garcia-Suarez
Date:
March 9, 2002 13:03
Subject:
Re: TPR1 post-mortem
Message ID:
slrna8kucq.br0.rgarciasuarez@rafael.example.com
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
Thread Previous
|
Thread Next