Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Just FYI, in a module "included" by use, executable statements in "file scope" are being run inside a begin block.

From the documentation for use, use Module LIST; is the same as:

BEGIN { require Module; Module->import( LIST ); }

The reason for using a BEGIN block in a module to execute some code before the module is completely compiled. Even without the BEGIN block, any "file scope" statements will get executed before anything after the use is compiled (then run).

As for the desirability of file scope code in a module, by design, Perl expects a "used" module to run init/sanity-check code at "use time". This is why most modules end with 1;. Perl is expecting the module to "return" a true value if everything is "A-Okay". Otherwise, a false value tells Perl something went wrong. Fetching the current working directory is a reasonable init action. Of course, if you are more comfortable using a BEGIN block, that's fine, too. TIMTOWTDI.


In reply to Re^4: How to determine absolute path of current Perl file? by RonW
in thread How to determine absolute path of current Perl file? by hakonhagland

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-24 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found