in reply to Problem with Perl Modules.

Declaring that you are going to export a variable isn't the same as declaring a variable. Under use strict; you get an error when a global variable is used without being first declared. You can declare the variables with our (i.e. something like our $TestCase;) or use vars (i.e. something like use vars qw( $TestCase );)

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re^2: Problem with Perl Modules.
by nisha (Sexton) on Oct 26, 2005 at 08:32 UTC
    Thanks a ton for your help.It works after i declare the variables in our. Right now i am facing another problem; my perl module has functions too, and i want to access these functions from the scripts which uses the perl module.
    package Hello; use Exporter; @ISA = ('Exporter'); # create an Exporter object. # Export all variables and functions via EXPORT statement # updated for exporting Setup CLI keys and Variables our($x,$test,$TestCase); @EXPORT = qw($x $test $TestCase ReadConfigFile);
    In my perl module i have written the subroutine for ReadConfigFile. I have another perl script which uses this perl module Hello and invokes ReadConfigFile from the script. When i ran my script it gives me
    Undefined subroutine &Hello::ReadConfigFile called at C:\Test\Hello.pl + line 30.
    I do not know if i am missing out on something. Please help. Thank You

      I think we'll need a little more info before we can help with this. Unless I'm missing something, from what you've told us, it should work. I would first double check the spelling of your "ReadConfigFile" where you define it. You could get this error if your sub is actually typo'd as "ReadConfgiFile" for instance.

      Aside from your error, I do have a couple quick observations...

      • Your comment "create an Exporter object" doesn't describe what's going on in that line. It actually makes your Hello module inherit from Exporter.
      • Your @ISA and @EXPORT variables should also be declared using our.
      • You might want to consider using @EXPORT_OK instead of @EXPORTin order to avoid cluttering your scripts' namespaces by default.

      -sauoq
      "My two cents aren't worth a dime.";