Should I use "use 5.12.0, use warnings"; in the perl module?

I'm not sure what and what's the difference if you run the perl module with

package MYPACKAGE;
use 5.12.0;
use warnings;

# functions are here

1;

or

use 5.12.0;
use warnings;
package MYPACKAGE;

#  functions are here

1;

or if these use ...are not considered at all, since they use ...are inherited from the perl script.

The question probably boils down to: is it worth specifying those use ...in the module or is it enough if I specified them in my perl script.

+5
source share
1 answer

Pragmatic modules have a lexical rather than a dynamic domain.

The pragma version activates certain functions in the current area, depending on the version. It does not activate these features worldwide. This is important for backward compatibility.

, , :

# this is package main
use 5.012; # activates `say`
package Foo;
say "Hi"; # works, because lexical scope

, (!= scope).

warnings .

use strict, accross. :

Foo.pm:

say "Hi";
1;

main.pl:

use 5.012;
require Foo;

.


, , . package, , .

use 5.012; use warnings;

package Foo;
...;
package Bar;
...;
1;

package, .

package Foo;
use 5.012; use warnings;
...;
1;

, use: -)

+7

All Articles