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

I have a perl module called encrypt.pm that I call to do string encryption.

I have another module called utmysql.pm that makes calls to encrypt.pm and has a 'use encrypt.pm' statement in it.

I'm writing a script (lets call it test.pl) that calls both encrypt.pm and utmysql.pm with 'use' statements.

If I try calling a function (called randsalt) from encrypt.pm in test.pl I get an error messages says :

--

Undefined subroutine &main::randsalt called at ./test.pl line 8

---

I comment out 'use utmysql' test.pl works fine. I've tried calling randsalt as &randsalt and &encrypt::randsalt but I still run into the same problem. Suggestions?

Replies are listed 'Best First'.
Re: modules within modules...a question
by Crian (Curate) on Apr 01, 2004 at 15:42 UTC
    You have to export that function in encrypt.pm or better call it fully quallified as Encrypt::randsalt() if your package name is Encrypt.
Re: modules within modules...a question
by dragonchild (Archbishop) on Apr 01, 2004 at 15:43 UTC
    You'll need to post the modules (removing the bodies of the functions, please) and the script portion where you bring in the modules in order for us to say anything useful. There are dozens of reasons why this might be failing.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

      No, I think the error message

      > Undefined subroutine &main::randsalt called at ./test.pl line

      indicates, that he tries to call randsalt in the main package, where is no randsalt. So I think (as I posted above), that he forgot to qualify the name or to export the function.

      What else reason could lead to that error message?