in reply to Re^3: Using guards for script execution?
in thread Using guards for script execution?
You can include other Perl files to your heart's content, and unless you explicitly export things (from the included file (in Python, an import), you'll never be able to see them within your current namespace.
Unless you fully qualify the symbol name. Package globals are truly global if fully qualified.
... useing a Perl file does not execute it, so any executable code you have in a Perl file will not be run when including it into another Perl file. ... main() code ... will not be executed or evaluated (into) when including said file in another file.
Files that are use-ed (e.g., .pm files) are evaluated. That's where the necessary true return value comes from at the end of the module.
File MainGuard.pm;
# MainGuard.pm 28feb17waw package MainGuard; use warnings; use strict; main(@ARGV); sub main { my (@args, ) = @_; printf "in function %s() \n" . "with arguments %1\$s(@args) \n" , (caller(0))[3] ; die "AAAAAAAArrrrrgh..."; # but how did he chisel it in stone? } 1;
File execution_of_used_module_1.pl:
use warnings; use strict; use MainGuard; print "in package ", __PACKAGE__, " before exit. \n"; exit(0);
c:\@Work\Perl\monks\R0b0t1>perl execution_of_used_module_1.pl Command +Line Args in function MainGuard::main() with arguments MainGuard::main(Command Line Args) AAAAAAAArrrrrgh... at MainGuard.pm line 20. Compilation failed in require at execution_of_used_module_1.pl line 86 +. BEGIN failed--compilation aborted at execution_of_used_module_1.pl lin +e 86.
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Using guards for script execution?
by stevieb (Canon) on Mar 01, 2017 at 02:12 UTC | |
by AnomalousMonk (Archbishop) on Mar 01, 2017 at 02:52 UTC |