When I execute the following code, I get Can't locate SomePackage.pm in @INC ....
BEGIN {
die;
use SomePackage;
}
Why is use executed before die?
use SomePackage is exactly equivalent to
BEGIN { require SomePackage; SomePackage->import }
A BEGIN code block is executed as soon as possible, that is, the moment it is completely defined. The second BEGIN (which is implied by use) is completely defined first, and is thus executed first.
From http://perldoc.perl.org/functions/use.html
Because use takes effect at compile time, it doesn't respect the ordinary flow control of the code being compiled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With