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);
Output:
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:  <%-{-{-{-<


In reply to Re^4: Using guards for script execution? by AnomalousMonk
in thread Using guards for script execution? by R0b0t1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.