On Thu, May 12, 2005 at 09:06:48PM +0100, Benjamin Smith wrote: > sub foo { my $x; BEGIN { $x = 3 }; say $x } > foo; foo; foo; > > Currently in perl5 and pugs this prints "3\n\n\n". > > Should BEGIN blocks be able to modify values in lexical variables that > don't really exist yet? (People can use state after all to get a > variable which does exist early enough for them to modify.) > > > Is there some kind of "prototype pad" (and lexicals) available inside > the BEGIN block, rather than a full runtime pad?
In perl5, the first instance of a lexical exists from the moment of compilation through till first exit from the enclosing scope during exection. If this wasn't the case then lots of closure-related stuff wouldn't work, eg { my $count = 0; sub inc { $count++ } sub dec { $count-- } } ... -- print+qq&$}$"$/$s$,[EMAIL PROTECTED],$:$.$q$^$,[EMAIL PROTECTED];$.$q$m&if+map{m,^\d{0\,},,${$::{$'}}=chr($"+=$&||1)}q&10m22,42}6:[EMAIL PROTECTED];^2dg3q/s"&=~m*\d\*.*g