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

Hi Monks,

this is really one of the moments I would like to change my
profession (or hobby for that matter). It all started with
imported symbols being undefined (for no visible reason). So
I striped it down until I have nearly verbatim the example of
the camel book.

File 1:

#!/usr/bin/perl -w use strict; use Test qw(dummy); #print $config{path}; &dummy;
File 2:

package Test; use strict; use Exporter; my %config = ( lexpath => '/home/rj/proj/elric/lexika/', silence => 0, ); @ISA = qw(Exporter); @EXPORT_OK = qw(dummy); BEGIN { } sub dummy { print "aha"; } END { } 1;
And now for the fun. Perl 5.6.0 on my Linux Box says (it didnīt
before):

rj@proxima:~/proj/elric/src > test.pl
"dummy" is not exported by the Test module at ./test.pl line 4
Can't continue after import errors at ./test.pl line 4
BEGIN failed--compilation aborted at ./test.pl line 4.
And that was it. Iīd gladly pull my hair if I had any left.
I donīt see the error. I tried to export %config
but to no avail. Do you have more insight?

Ciao

Replies are listed 'Best First'.
Re: Exporter is driving me mad
by rucker (Scribe) on Jul 18, 2001 at 01:01 UTC
    You're probably using the Test.pm that is part of the distribution. This reminds me of the people that compile some program as test, type test at the command prompt and wonder why it doesn't behave right. Of couse I could be off...
Re (tilly) 1: Exporter is driving me mad
by tilly (Archbishop) on Jul 18, 2001 at 01:23 UTC
    rucker has it right. You are pulling up the wrong Test.pm. For future reference the easiest way to discover this is to put a print statement in your Test.pm and see that it isn't triggered. Second easiest is:
    perldoc -m Test
    which will show you the text of what it is picking up as Test. If that doesn't look familiar, you picked up the wrong module.

    Next on the list you can try:

    perl -e 'use Test; print $INC{"Test.pm"};'
    which will tell you where you picked up that module from. And finally if you really want it to take your module you can use lib. But I don't recommend doing that, if you don't have good reason, just stay away from the names of core modules.

    UPDATE
    Oops, Converter pointed out that $INC{Test} is not what you want. It is $INC{"Test.pm"}. You need to convert from a fully qualified package name, that means turn :: into / and add .pm at the end. My bad.

Re: Exporter is driving me mad
by converter (Priest) on Jul 18, 2001 at 01:19 UTC

    rucker is exactly right. "test" is a four-letter word because when you use it you're almost always likely to run into some sort of name collision, whether it's in Perl, or in the shell.

    Note that when you ask perl to require Test, you end up with the Test.pm module that is included with the Perl distribution:

    $ perl -le 'use Test; print $INC{"Test.pm"}' /usr/lib/perl5/5.6.1/Test.pm

    conv

Re: Exporter is driving me mad
by lestrrat (Deacon) on Jul 18, 2001 at 01:19 UTC

    I think rucker is correct. If I rename the module name to myTest.pm ( and added use vars qw/ @ISA @EXPORT_OK /) , it worked for me