# Foo.pm my $shell = $ENV{'SHELL'} || ""; BEGIN { if ( $ENV{'SHELL'}) { print "\$ENV{'SHELL'} is $ENV{'SHELL'}...\n"; } else { print "\$ENV{'SHELL'} is not set...\n"; } if ( $shell ) { print "\$shell is $shell...\n"; } else { print "\$shell is not set...\n"; } } 1;
Now, the perl script, "foo" has nothing but:
#!/usr/bin/perl use Foo; print "done.\n";
Running the program should be self-explanitory. The question is: if "use" is an implicit BEGIN, and there is no precedence to the orders of the BEGIN blocks, then why isn't "$shell" set outside of the BEGIN block on Foo.pm?
And, as far as Randall's comment about environment variables not set at the time of BEGIN, then what explains the behavior of this sample program?
In reply to Re^4: What is the scope of BEGIN? Or... when does it "begin?"
by argv
in thread What is the scope of BEGIN? Or... when does it "begin?"
by argv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |