On Sun, Mar 16, 2003 at 09:37:51PM +0200, Enache Adrian wrote: > 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 ? yes, except for (2), which I would put as an anon sub so you get a new closure for each execution: 2. sub a { my $x; my $p = qr/(?{ $x++ })/; $_ =~ $p } => sub a { my $x; my $p = sub { $x++ }; $p->() } Whether it's practical to implement (1)..(3), and let alone what it would do to backwards compatibility, I don't really have a feel for right now. I'm also not certain whether it's fair on users to have (1) and (2) implemented differently - that could cause suprises. eg does my $x; $p = 'hello'; /$p(?{$x})/ get treated as case (1) or (2)? (Disclaimer: I do bug fixes, not language design. Hence my general vagueness here.) -- "You're so sadly neglected, and often ignored. A poor second to Belgium, When going abroad." Monty Python - "Finland"Thread Previous | Thread Next