Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

When you use your module, use require's your module. This is explained in the documentation for use.

require includes your module by evaluating it with do. This is explained in the documentation for require.

If your module compiles successfully, do returns the value of the last expression evaluated. When you end your module with 1;, this value is 1. This is explained in the documentation for do.

require checks the value returned by do and if it is false it dies with the error $filename did not return true value, where $filename is the full path name of the file being loaded (your module).

So, as others have pointed out, it is not necessary that your module end with 1; but if you want to include it with use or require then the last expression evaluated must have a true value. Ending modules with 1; is merely a convention to ensure they return a true value.

Note that you can include a module that ends with 0; (or any other expression that evaluates to a false value. You can't include it using use or require, but you can use do and ignore the return value or load the content into a scalar and use eval to evaluate the scalar and, again, ignore the return value.


In reply to Re: Perl Module ending without 1; by ig
in thread Perl Module ending without 1; by prantikd

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (8)
    As of 2014-08-21 02:59 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (127 votes), past polls