On Sun, Mar 16, 2003 at 12:58:19PM +0000, Dave Mitchell wrote:
> Perhaps bare regexs should be demoted to blocks and qr// should be
> promoted to full anon sub status, so that they get cloned on each execution
> of qr// ???
>
> Although I have to say that personally I don't like the idea of sharing
> the same pad, simply becuase of run-time compilation, eg
>
> for (1..1_000_000) {
> $p = '(?{my $x; ...})'; /$p/;
> }
>
> This causes the pad to get filled with a million slots for defunct $x's.
> Eval's have their own pad to avoid this sort of thing.
I see three cases there - with their moral equivalent.
1. sub a { my $x; /(?{ $x++ })/ }
=> sub a { my $x; { $x++ } }
2. sub a { my $x; my $p = qr/(?{ $x++ })/; $_ =~ $p }
=> sub a { my $x; sub clos { $x++ }; clos }
3. sub a { my $x; my $p = '(?{ $x++ })'; /$p/ }
=> sub a { my $x; eval '$x++' }
Does it look correct to you ?
Regards
Adi