I need to import all our variables from an unnamed Perl module (Module.pm) and use them inside a Perl script (Script.pl).
The following code works well without "strict use , but failed with it. How can I change this code to work with " use strict " without manually listing all imported variables (as described in the answer to another question )?
Many thanks for your help!
Script.pl:
use strict; require Module; print $Var1;
Module.pm:
our $Var1 = "1\n"; ... our $VarN = "N\n"; return 1;
Run the script:
$> perl Script.pl
Errors:
Global symbol "$Var1" requires explicit package name at Script.pl line 3. Execution of Script.pl aborted due to compilation errors.
NOTE (1) : the module has no name, so using the module Module:: prefix is ββnot an option.
NOTE (2) : Module.pm also contains a set of functions configured by global variables.
NOTE (3) : variables are different and should NOT be stored in the same array.
NOTE (4) : the design is NOT good, but the question is not the design. This is about forcing the specified code to work with minimal changes with O(1) complexity, that is, several lines of code that are independent of N
Candidate for Solution (ACCEPTED) : Add $:: in front of all imported variables. It conforms to strict , and also allows you to distinguish between my and imported variables in code.
import module global-variables perl
aponomarenko
source share