Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: End of subroutine

by marcussen (Pilgrim)
on Nov 07, 2008 at 05:21 UTC ( #722156=note: print w/ replies, xml ) Need Help??


in reply to End of subroutine

It is used outside the subroutine, your question is actually: why is 1; used at the end of a module?

A use statement (as in use module;) evals the contents of a file. The last expression in the file must evaluate to true, or the eval dies.

UPDATE: Correction of my statement by ikegami (see below);
Confucius says kill mosquito unless cannon


Comment on Re: End of subroutine
Re^2: End of subroutine
by ikegami (Pope) on Nov 07, 2008 at 05:29 UTC

    A use statement (as in use module;) evals the contents of a file. The last expression in the file must evaluate to true, or the eval dies.

    Not quite. eval never dies based on the value returned by the evaluated expression.

    >perl -e"eval { 0 }" >

    require (and thus use) dies if the values returned by the module is false.

    >copy nul Module.pm 1 file(s) copied. >perl -e"use Module;" Module.pm did not return a true value at -e line 1. BEGIN failed--compilation aborted at -e line 1. >echo 1; > Module.pm >perl -e"use Module;" >

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2015-07-04 17:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls