develooper Front page | perl.perl6.language | Postings from May 2005

BEGIN and lexical variables inside subroutines

Thread Next
Benjamin Smith
May 12, 2005 13:07
BEGIN and lexical variables inside subroutines
Message ID:
  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?

Benjamin Smith <,>

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About