http://www.perlmonks.org?node_id=781340


in reply to Perl Module ending without 1;

When you use your module, use require's your module. This is explained in the documentation for use.

require includes your module by evaluating it with do. This is explained in the documentation for require.

If your module compiles successfully, do returns the value of the last expression evaluated. When you end your module with 1;, this value is 1. This is explained in the documentation for do.

require checks the value returned by do and if it is false it dies with the error $filename did not return true value, where $filename is the full path name of the file being loaded (your module).

So, as others have pointed out, it is not necessary that your module end with 1; but if you want to include it with use or require then the last expression evaluated must have a true value. Ending modules with 1; is merely a convention to ensure they return a true value.

Note that you can include a module that ends with 0; (or any other expression that evaluates to a false value. You can't include it using use or require, but you can use do and ignore the return value or load the content into a scalar and use eval to evaluate the scalar and, again, ignore the return value.