Is there a good standard?
It's very common to simply end with 1;. It's needed, because perl uses the last expression that was evaluated to determine if the module was loaded correctly. When it's not there, but the module still works, that means the last expression was true, but it's considered bad style to depend on that.
I've also seen people use strings over there (q/Murphy's law is recursive. Washing your car to make it rain doesn't work./;), or 42;, and other values representing truth.
44696420796F7520732F2F2F65206F
7220756E7061636B3F202F6D736720
6D6521203A29202D2D204A75657264
| [reply] |
AFAIK the placement of the return 1; (or just 1;) in the module file makes no difference.
Michael
| [reply] |
Actually it can make a difference in two ways.
The first is that if you put a return before some code
that you want executed, it won't be because you returned.
The second is that if you just use a true value but don't
return, and accidentally put some executable code after it
(eg a variable initialization) with a false value, then
your module will fail to load.
Both should be obvious if you are bitten by them. But I
like putting the true return value at the end anyways.
| [reply] |
That makes sense - thanks.
Michael
| [reply] |
Not that it's yet a concern, I believe (but could not find the evidence!) it was announced that in Perl 6 modules will no longer be required to return true. (And where is that Exegesis 4 anyway? ;^)
..Guv
| [reply] |