What happens if you do not bet 1; at the end of the package?

What happens if you do not put 1;at the end of the package? For example, if I remove 1;from the following script, the code still works:

#!/usr/bin/perl

package Foo;
print "Begin and Block Demo\n";

BEGIN { 
    print "This is BEGIN Block\n" 
}

END { 
    print "This is END Block\n" 
}

1;

Is it 1;required to create a package? I saw this question , but it does not explain what will happen if 1;omitted.

+4
source share
2 answers

This is a bit complicated. It is simply required if the package is downloaded useor require.

From require

true , , 1;, , true . 1;, .

use require, , use , true, . , 1; . use ( require), 1 (true).

, use, , true, require. -, "".

, , require . use , . , 1; .

perlmod .


.

Mod.pm

package Mod;

# print "hello\n";    # works with this line uncommented

script.pl

use Mod;

perl script.pl

Mod.pm did not return a true value at main.pl line 1.
BEGIN failed--compilation aborted at main.pl line 1.

use d, . , true, print, .

perl Mod.pm , .

+6

use a .pm , (, 1), , use , .

, , ; , .pm, 1, use -able. , script, 1.

+3

Source: https://habr.com/ru/post/1667946/


All Articles