No, that isn't legitimate. A used/required file should always have a package that matches its name. You could export said vars, though.
package includee; use strict; use warnings; use Exporter qw( import ); # I prefer to use `@EXPORT_OK` # and list the imported things # in the `use` statement. our @EXPORT = qw( $SHAREDVARIABLE1 @SHAREDVARIABLE2 %SHAREDVARIABLE3 function ); # Using `use vars` is ok, but dated. our $SHAREDVARIABLE1; our @SHAREDVARIABLE2; our %SHAREDVARIABLE3; sub function { ... } 1; # Modules must end with a true value.
Note that it's usually better to export subs that manipulate the variables rather than exporting the variables themselves. It provides better encapsulation, which has a large number of benefits.
If you want to load a module that's in the same dir as the script, you should add the following to the script:
use FindBin qw( $RealBin ); use lib $RealBin;
In reply to Re: Common subs and Global Variables
by ikegami
in thread Common subs and Global Variables
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |