develooper Front page | perl.perl5.porters | Postings from March 2003

Re: (?{ .. })'s and lexicals: A fix ([perl #9010], [perl #8817], [perl #8030], etc)

Thread Previous | Thread Next
From:
Enache Adrian
Date:
March 16, 2003 11:32
Subject:
Re: (?{ .. })'s and lexicals: A fix ([perl #9010], [perl #8817], [perl #8030], etc)
Message ID:
20030316193751.GA840@ratsnest.hole
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

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About