0

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.
4
  • Did you mean for base.pm and mathlib.pm to be different? Commented Aug 16, 2013 at 9:25
  • how does mathlib.pm look like? Commented Aug 16, 2013 at 9:26
  • See stackoverflow.com/questions/2648517/… Commented Aug 16, 2013 at 9:32
  • Sorry its not base.pm but mathlib.pm Commented Aug 16, 2013 at 9:49

1 Answer 1

1

$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.

Sign up to request clarification or add additional context in comments.

4 Comments

Name "mathlib::def_name" used only once: possible typo at main.pl line 8.
I tried with the following, print $mathlib::def_name; but its showing the err Name "mathlib::def_name" used only once: possible typo at main.pl
Does mathlib.pm have a package declaration at the top, i.e. package mathlib;?
thanks for the help. i tried as in the link mentioned by Himanshu. it helped. thank u

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.