Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://781340]
help
Chatterbox?
[marioroy]: that is funny, made me smile. miss those days
[marioroy]: thank you, humor of the day stevieb++
[1nickt]: Sad that so much of our humour these days is dry, wry, gallows humor :-/
[1nickt]: One of the great human characteristics .... to laugh in the face of doom :-)

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2017-03-26 18:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (315 votes). Check out past polls.