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

Hello,
I've tried searching for an answer, but if I missed it somewhere, please point me in the right direction.

I've always disliked having 1; at the bottom of my modules so that the last statement returns true. I find it very easy to miss and accidently remove, nor does it fit with my preferred style of coding.
I'd like to know if it is acceptable to use return(1); in its place. It seems to work just fine, but would like to know if there are any differences or pitfalls in doing it this way.

Thanks in advance.

Replies are listed 'Best First'.
Re: Is it okay to return(1) instead?
by Zaxo (Archbishop) on Nov 20, 2001 at 04:04 UTC

    Any statement which evaluates true will do. A version string, copyright declaration, or "0 but true" are all usable.

    After Compline,
    Zaxo

      Any statement which evaluates true will do.

      The funniest of these I've seen seen at the bottom of a module was   "Other side up";

      Thank you for your very timely response.
      I appreciate it.
Re: Is it okay to return(1) instead?
by no_slogan (Deacon) on Nov 20, 2001 at 05:14 UTC
    According to perlfunc:require,
    The file is included via the do-FILE mechanism, which is essentially just a variety of "eval".
    Returning from an eval does what you want, so go ahead and use return(1) if you like.

    Personally, I always like to end my modules with:

    1 # end of Foo.pm
    It's hard to miss. It tells you where the end is supposed to be, so you know if you lost the last page of your printout. And leaving off the final semicolon means it's likely not to compile if someone tries to add code after it.
Returning happiness
by petdance (Parson) on Nov 20, 2001 at 10:21 UTC
    I either use
    1; # return happiness
    or sometimes
    "happy"

    xoxo,
    Andy
    --
    <megaphone> Throw down the gun and tiara and come out of the float! </megaphone>

      My most recent attempt in this regard (which will, alas, probably have to get deleted before it goes to the client) is

      "My name is Inigo Montoya. You killed my father. Prepare to die.";



      If God had meant us to fly, he would *never* have given us the railroads.
          --Michael Flanders

        "This return value left intentionally blank"
        - or -
        "A true return value for the module"

        I think Dominus had something about nose hairs in one of his...

Re: Is it okay to return(1) instead?
by chromatic (Archbishop) on Nov 21, 2001 at 10:47 UTC
    If anyone reads all the way through one of my modules, there ought to be a reward. I often quote literature or poetry, or invoke she who must be named. (You'll have to get on her good side first, though.)

    Oh, yeah. Browse the core Perl test suites for more fun, when 5.8 snapshots come out. :)

Re: Is it okay to return(1) instead?
by graq (Curate) on Nov 20, 2001 at 14:58 UTC