in reply to Re: Re: Returning information from BEGIN
in thread Returning information from BEGIN
Note that there is no problem with:
my $Err; BEGIN { $Err= defined $ENV{SM} }
Sure, the BEGIN happens at compile time but so does the declaration part of the my code. use strict didn't give you an error, did it? That is because $Err is getting declared at compile time before the BEGIN block is executed.
What would be a "problem" is code like this:
because the my statement gets executed in two parts. The declaration part gets executed at compile time while the initialization part gets executed at run time. So the order or execution ends up looking more like this:my $Err= 0; BEGIN { $Err= 1 if ! $ENV{SM} }
O-:my $Err; $Err= 1 if ! $ENV{SM}; $Err= 0;
Personally I prefer the my solution to using use vars inside the BEGIN block.
- tye (but my friends call me "Tye")
|
|---|