in reply to Re^3: What is the scope of BEGIN? Or... when does it "begin?"
in thread What is the scope of BEGIN? Or... when does it "begin?"
# 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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: What is the scope of BEGIN? Or... when does it "begin?" (steps)
by tye (Sage) on May 06, 2005 at 17:44 UTC | |
by argv (Pilgrim) on May 06, 2005 at 17:54 UTC | |
by tye (Sage) on May 06, 2005 at 18:02 UTC |