Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
The stupid question is the question not asked
 
PerlMonks  

Re: Perl Module ending without 1;

by ig (Vicar)
on Jul 18, 2009 at 14:56 UTC ( #781340=note: print w/ replies, xml ) Need Help??


in reply to Perl Module ending without 1;

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.


Comment on Re: Perl Module ending without 1;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://781340]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2014-04-17 23:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (458 votes), past polls