If it was loaded via require or use, yes, it is only compiled and executed the first time. It's import method will be called each time, allowing symbols to be exported into multiple namespaces.
# script.pl use Module1; use Module2;
# Module1.pm package Module1; BEGIN { print("Compiling Module1\n"); } use Module2; sub import { print("Module1 exporting to ". caller() . "\n"); } print("Executing Module1\n"); 1;
# Module2.pm package Module2; BEGIN { print("Compiling Module2\n"); } sub import { print("Module2 exporting to ". caller() . "\n"); } print("Executing Module2\n"); 1;
>perl script.pl Compiling Module1 Compiling Module2 Executing Module2 Module2 exporting to Module1 Executing Module1 Module1 exporting to main Module2 exporting to main
>perl script.pl | sort Compiling Module1 --> once Compiling Module2 --> once Executing Module1 --> once Executing Module2 --> once Module1 exporting to main --> once per "use" Module2 exporting to main \ Module2 exporting to Module1 --> once per "use"
In reply to Re^3: modules using things from other modules
by ikegami
in thread modules using things from other modules
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |