in reply to use and BEGIN
foo.pm:
package foo; BEGIN { print "foo's BEGIN\n"; } print "foo's body\n"; sub import { shift @_; print "foo's import: @_\n"; } 1;
bar.pm:
package bar; use foo qw(from bar); 1;
test.pl:
use lib '.'; use foo qw(from test.pl); use foo qw(from test.pl again); use bar;
Output:
BEGIN blocks are executed at compilation. use and require don't compile the same code twice.$ perl test.pl foo's BEGIN foo's body foo's import: from test.pl foo's import: from test.pl again foo's import: from bar $
Look in perlvar under %INC for more info:
The "require" operator uses this hash to determine whether a particular file has already been included.
blokhead
|
|---|