Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

END in packages

by Fingo (Monk)
on Aug 26, 2001 at 04:08 UTC ( #107870=perlquestion: print w/replies, xml ) Need Help??

Fingo has asked for the wisdom of the Perl Monks concerning the following question:

I am writinga module for my use, and if I just leave a 1; as the last line, everything works fine. If I however use an END block
END { 1; }
it does not return true. What's wrong?

Replies are listed 'Best First'.
Re: END in packages
by rchiav (Deacon) on Aug 26, 2001 at 04:16 UTC
    END is for the module cleanup code. Your module must return true, hence the 1. END is basically a destructor, and won't be returned the same as the last line of the file.

    You might want to read perlmod

    Hope this helps..
    Rich

Re: END in packages
by John M. Dlugosz (Monsignor) on Aug 26, 2001 at 04:37 UTC
    The loader cares about the last statement executed, and that will be the main-line code. The creation of a sub, even a special one like END, doesn't cause the contents of that sub to be run--your 1 is not seen 'till it's called. END is not called when a module is loaded, but when it's terminated.

    In a related thread, the idea of using return 1; at the end of the module was raised, as being clearer.

      But stylistically something has to be said for ending with:
      "Just another Perl hacker,\n";
        True enough (Pun intended).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2020-12-02 22:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (47 votes). Check out past polls.

    Notices?