Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
710 views
in Technique[技术] by (71.8m points)

return value - Why the 1 at the end of each perl package?

If you forget the 1 at the end of a package, Perl tells you "The package didn't return a true value". Well, if it knows you forgot it, why not just put it there for you?

question from:https://stackoverflow.com/questions/5293246/why-the-1-at-the-end-of-each-perl-package

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Because Perl modules are required to return a value to signal if the require directive must succeed (true value returned) or fail (false value returned; this can make sense if the module failed to initialize for some reason).

If you don't return anything, the interpreter cannot know if the require must succeed or fail; at the same time, since it's easy to forget to put the true value at the end of the package, it suggests the "common fix" for this error: add a true value as a return.

For some other info/folklore about the modules return value have a look at this question.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...