in reply to Perl Bug in Regex Code Block?
That code prints 600. If, however, you cause the regex to change, such that it requires recompilation, the binding to the previous @x is gone, and the new @x is bound.### update: fixed ### thanks Hof -- I condensed working code poorly :( use re 'eval'; my @r; my $p = q/.(?{ ++$x[0] })^/; for (0..2) { my @x = (0); "ab" =~ $p; push @r, \@x; } print "$_->[0]" for @r;
If you were to use qr// instead, you'd be changing the global array.
You're doing some funny-looking scope-crufting. I'd stay away from it if I were you. This situation is the sort of thing I fear having to write about and explain in my book.
_____________________________________________________
Jeff[japhy]Pinyan:
Perl,
regex,
and perl
hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re2: Perl Bug in Regex Code Block?
by Hofmator (Curate) on Sep 03, 2001 at 19:41 UTC | |
by japhy (Canon) on Sep 03, 2001 at 20:13 UTC |