Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: How to end a Perl script

by Dog and Pony (Priest)
on May 02, 2002 at 19:56 UTC ( #163655=note: print w/ replies, xml ) Need Help??


in reply to How to end a Perl script

Case number one is used for Packages and Modules, which require (no pun intended) that they end in (= return) a true value. You will also see this one, or any other true value ending packages in the middle of a file if there are several packages in the same one.

Otherwise, just let it fall off the end when possible, and use exit in all other cases. That is by far the cleanest and most readable (and will continue to be the last statement even if someone by mistake adds code after BOTTOM:).


You have moved into a dark place.
It is pitch black. You are likely to be eaten by a grue.


Comment on Re: How to end a Perl script
Download Code
Re: Re: How to end a Perl script
by samtregar (Abbot) on May 02, 2002 at 23:08 UTC
    You will also see this one, or any other true value ending packages in the middle of a file if there are several packages in the same one.

    You are correct that you will see this, but it's utterly unnecessary. The true value is there to placate "require." It has absolutely nothing to do with "package." Ending every package with "1;" is like buying a ticket on the Cargo Cult Express.

    -sam

      That is true, as I am aware of (see my no-pun remark above). I still put them there, to a) mark the end of a package in an easily readable way (yes, I want that in addition to a new package declaration), and b) so I won't forget it if I decide to move it to a separate file. Cargo Cult or no, I see no error in that practice, at least not for those reasons?

      But it is ok to point that difference out, of course.


      You have moved into a dark place.
      It is pitch black. You are likely to be eaten by a grue.
        Cargo Cult practices are very rarely "wrong" in the sense of causing bad results. More often they are, like this one, just plain unnecessary. Instead of a cryptic "1;" you could write "# end of package Foo::Bar." And if you're worried about forgetting the "1;" when you move the package to a new file, well, don't. Perl will be happy to remind you when you try to load the new file!

        -sam

      __END__ Anything past that is treated as a comment.
Re: Re: How to end a Perl script
by Anonymous Monk on May 03, 2002 at 16:05 UTC
    if (caller) {return} else {exit}; "exit" is a pain if later you decide to call the scritp from somewhere else with a "do".

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2014-09-17 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (56 votes), past polls