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

Hi, I have created a package Testpm with about three simple subroutines. i have identified the package using the "package testpm" and have terminated with a "1;" when referenced in a pl file and one of the subroutines "&getList" is called the fillowing error is thrown while compileing . Undefined subroutine &main::getList called at testmodule.pl line 9. kindly advice. Anandatirtha
  • Comment on what are the requiremetns for packaging

Replies are listed 'Best First'.
Re: what are the requiremetns for packaging
by grep (Monsignor) on Oct 28, 2002 at 05:39 UTC
    As you have stated, you created these subs in the package 'testpm'. When you run your program you're in the 'main' package (hence the error message Undefined subroutine &main::getList).

    What you need do is either access your subs using a fully qualified name (eg. testpm::getList), export your subroutines to the main namespace using Exporter, or create your module as an object and turn your subs into methods (explained in perlboot, perltoot, perltooc, and perlbot).

    If you choose the object method then I would also recommend TheDamian's book Object Oriented Perl



    grep
    Mynd you, mønk bites Kan be pretti nasti...
      Thanks grep !! It was helpful.. Anandatirtha