0
votes

I have a doubt in perl , I need to get filename in command line arguments/switches/options and based on that i need to include/require/use that file in my script. So by using that getopt variable am able to get it done. However if i have used "use strict" in my script i could not get it. Please help on this

I tried as follows and its working

base.pm:

our $def_name = "me";

main.pl:

my $name = "mathlib.pm";
require $name;
print $def_name;

When i include the follwoing lines in the main.pl and base.pm,

use strict;
use warnings;

I am getting error,

Global symbol "$def_name" requires explicit package name .
Execution of main.pl aborted due to compilation errors.
1
Did you mean for base.pm and mathlib.pm to be different? - Barmar
how does mathlib.pm look like? - mpapec
Sorry its not base.pm but mathlib.pm - user2688842

1 Answers

1
votes

$def_name hasn't been exported from mathlib.pm, it's a package variable not a global. $mathlib::def_name will work, or you can use the Exporter module to export it into the namespace of any module which uses it.