nisha has asked for the wisdom of the Perl Monks concerning the following question:

Thanks a ton for your help monks. The variable declaration using "our" solved my previous problem.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

Replies are listed 'Best First'.
Re: Problem with functions in modules
by Corion (Patriarch) on Oct 26, 2005 at 09:11 UTC

    So, did you actually declare the subroutine ReadConfigFile? It does not suffice to say that you will be exporting ReadConfigFile, you also need to write the code into a subroutine and that subroutine must be named ReadConfigFile. For example like the following:

    package Hello; sub ReadConfigFile { my ($file) = @_; warn "Reading of config file '$file' is not yet implemented."; };
      Yes i have written the subroutine ReadConfigFile in Hello.pm and from the script Hello.pl i am invoking ReadConfigFile.
      use Hello; ReadConfigFile();
      I have used this in Hello.pl and i have also tried use Hello qw(ReadConfigFile); instead of use Hello; I have multiple functions in the @EXPORT, is there any particular order that i need to follow, i tried lot of sites..i am just not able to figure out why it throws "Undefined subroutine &Hello::ReadConfigFile at c:\test\hello.pl in line 30". Please help..

        Maybe then it could help us to further see what you're doing wrong if you showed us the code of ReadConfigFile. Please read and understand How (not) to ask a question to help us to answer your questions in a better way.

Re: Problem with functions in modules
by pajout (Curate) on Oct 26, 2005 at 09:25 UTC
    I recommend Advanced Perl Programming by Sriram Srinivasan. The chapter describing modules is easy to read and very informative.
Re: Problem with functions in modules
by chanakya (Friar) on Oct 27, 2005 at 07:00 UTC
    Hi nisha, Below is a sample code that calls a ReadConfig() from the module. This should get you started in your work.
    package Skywalker; require Exporter; @ISA = qw(Exporter); use strict; our @EXPORT = qw(ReadConfig); sub ReadConfig { my ($file) = shift; warn " --- going to read config file: $file ---\n"; # more steps here } 1;
    now the calling file itself
    #!/usr/bin/perl use warnings; use strict; use Skywalker; ReadConfig('/tmp/simple.cfg');
    output:
    perl walktest.pl --- going to read config file: /tmp/simple.cfg ---
    Hope this helps. Good luck