3 ms·
Why do you need to return 1 though? That seems pretty ridiculous.
by mrottenkolber 12y ago
Why do you need to return 1 though? That seems pretty ridiculous.
- gamache 12y agoTechnically, you don't need to return 1; you need to return a truthy value. The string "Perl syntax is dumb and hateful" works just as well.
- bmn_ 12y agoBecause that's how [require](http://p3rl.org/require http://p3rl.org/require) works: > to indicate successful execution of any initialization code Other dynamic languages have problems with "half"-loaded code. This mechanism is a defense against that.
- jjn1056 12y agoIt has uses. Sometimes you can also use it to write code that runs like a script if called in script mode (what some people are calling a modulino. If you really hate it there's a number of packages on CPAN to make it disappear. Also new versions of Perl allow you to define a package scope and skip the '1;' Most Perl programmers don't use this yet since the benefit is very small and the cost is losing some back compatibility. Maybe in a few years it will be more common: package MyApp::Web { ... } Like a lot of things in Perl it has a use that might not be immediately evident. Its also possible a more elegant solution could have been found as well. Generally when I write real code I never notice it (the 1; is drowned out by docs and real code.