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

All I ask is why?

What is the purpose/point/benefit of tacking a 1; onto the end of all packages. It seems unique to the Perl language and looks really weird. I know it's to make packages evaluate as true but why do they have to be true?
If you can never leave it off why give the programmer the labour of adding it :)

Would 'end package' not look a lot better than 1? How are all these 1's useful to me.

Replies are listed 'Best First'.
Re: Appending 1 to package
by jwest (Friar) on Jan 08, 2002 at 21:46 UTC
    Well, if you like, you could use:
    'End of Package';

    As for the why's, require (which is automagically called as part of a use on a module) wants any initialization code that's run in the module to return a true or false value to indicate whether or not initialization was successful. Since false is implicitly returned instead of true, you have to specify.

    --jwest

    -><- -><- -><- -><- -><-
    All things are Perfect
        To every last Flaw
        And bound in accord
             With Eris's Law
     - HBT; The Book of Advice, 1:7
    
Re: Appending 1 to package
by merlyn (Sage) on Jan 08, 2002 at 21:46 UTC
    From perldoc perlfunc, subsection "require":
    Note that the file will not be included twice under the same specified name. The file must return TRUE as the last statement to indicate successful execution of any initialization code, so it's customary to end such a file with "1;" unless you're sure it'll return TRUE otherwise. But it's better just to put the "1;", in case you add more statements.

    -- Randal L. Schwartz, Perl hacker

Re: Appending 1 to package
by talexb (Chancellor) on Jan 08, 2002 at 23:24 UTC
    Anyway, don't worry, TheDamian said the 1; won't be required at the end of modules for Perl 6.

    --t. alex

    "Excellent. Release the hounds." -- Monty Burns.