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

I'm having a bit of trouble writing a module. My module has a function call "guid()". When I attempt to call it from my program, I get the following error:
Undefined subroutine &main::guid called at H:\bin\foo.pl line 11.
However, if I call my function as Guid::guid(), it works. Here's the calling program that doesn't work:
use Guid; print "Guid = " . guid() . "\n";
Nor does this work:
use Guid qw(guid); print "Guid = " . guid() . "\n";
But, this does work:
use Guid; print "Guid = " . Guid::guid() . "\n";
Here's my module's header (from Guid.pm):
package Guid; use strict; use warnings; use Math::BigInt; use Net::Address::Ethernet qw(get_address); BEGIN { use Exporter (); our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); $VERSION = 1.00; @EXPORT = qw(guid); %EXPORT_TAGS = (); } sub guid { my ($clockId, $netId) = $_; my $maxClockId = 2**14; my $clockIdOffset = 2**15; #Turn on Clock High bit my $timeOffset = "122192928000000000"; [...And On...]
I've written Perl modules before and have successfully exported the various functions in them. I know the problem is probably something very simple, but I can't figure out what I am doing wrong. So, why can't I seem to export guid() to my main namespace? What stupid detail am I leaving out?

Replies are listed 'Best First'.
Re: Exporting Module Functions
by ambrus (Abbot) on Jun 05, 2006 at 20:12 UTC

    You forgot to add Exporter to the @ISA of the package.

Re: Exporting Module Functions
by Fletch (Bishop) on Jun 05, 2006 at 20:12 UTC

    Your module never sets @Guid::ISA to indicate that it ISA Exporter, so the Exporter::import method never gets called on its behalf. See the Exporter documentation for more details.

Re: Exporting Module Functions
by tinita (Parson) on Jun 05, 2006 at 21:30 UTC
    use base qw(Exporter);

    see base
    also I don't see the need for a begin block here.

Re: Exporting Module Functions
by qazwart (Scribe) on Jun 06, 2006 at 13:04 UTC
    Yup. That was the problem. I forgot "@ISA = qw(Exporter);" which establishes that my module can export functions.

    I've sat there for days trying to figure this out and comparing my header of this module to headers of other modules. For some reason, I didn't notice this one missing line.

    Thanks.