in reply to is 1; at the end of a PM still necessary in 5.6.1 ?

Subroutine definitions don't have values becuse they're declarations, not expressions. Anonymous subroutine assignments, however, obviously evaluate to their post-assignment lvalues.

Your module probably reduces to this:
  
package Foo; ... 1; # or any expression that returns a true value sub bar { ... }
Because the subroutine declaration has no value, the value of the last expression before the subroutine is returned.

Simplifying, it's a good thing to end your modules with a `1;', though in reality, only the last evaluated expression needs to return a true value for Perl to load your module.

   MeowChow                                   
               s aamecha.s a..a\u$&owag.print
  • Comment on (MeowChow) Re: is 1; at the end of a PM still necessary in 5.6.1 ?
  • Download Code

Replies are listed 'Best First'.
Re: (MeowChow) Re: is 1; at the end of a PM still necessary in 5.6.1 ?
by John M. Dlugosz (Monsignor) on Jul 22, 2001 at 10:30 UTC
    I see. So rather than a non-value-carrying statement causing the module's return value to not be true (undef or some more specific error), it is just ignored in favor of the last thing that was an expression.

    I suppose that's true in general?

Re: (MeowChow) Re: is 1; at the end of a PM still necessary in 5.6.1 ?
by mugwumpjism (Hermit) on Jul 23, 2001 at 16:34 UTC
    Simplifying, it's a good thing to end your modules with a `1;'

    How boring. I prefer 69; or "peace";.

    srand 3.14159; print join("", sort{rand 1<0.5}map{$_^"\037"}split m{ }x,"qmptk|z~wOzm??l]pUqx^k?j"),",\n";
      How boring. I prefer 69; or "peace";.

      One of my colleagues ends his modules with:

      42;