in reply to Trouble Exporting a Function

If that's the actual file then you need to change the use CART::Validate line to CART::Validate->import() e.g
use strict; use warnings; use diagnostics; use lib './lib'; ## was: use CART::Validate CART::Validate->import(); print qq(The module version is $CART::Validate::VERSION\n); my $testing = testMod(); print qq(The return value from testMod is $testing\n); exit; # CART::Validate package CART::Validate; BEGIN { use Exporter; our( @ISA, @EXPORT, @EXPORT_OK, $VERSION ); @ISA = qw( Exporter ); @EXPORT = qw( &testMod ); @EXPORT_OK = qw(); $VERSION = 1.00; } sub testMod { return "HELLO!"; } 1; __output__ The module version is 1 The return value from testMod is HELLO!
However you should really put everything below (and including) the line package CART::Validate into a file of it's own (i.e Cart/Validate.pm in one of the paths in @INC) and then your use statement will work fine.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Trouble Exporting a Function
by PodMaster (Abbot) on Mar 13, 2003 at 15:59 UTC
    I'm sorry, but that's not related to the error he gets (and neither is his snippet).


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
    ** The Third rule of perl club is a statement of fact: pod is sexy.

      I'm sorry, but that's not related to the error he gets (and neither is his snippet).
      His error is
      Undefined subroutine &main::testMod called at C:\path\path\modtest.pl +line
      His problem is that testMod() is not being imported into main. Calling import() explicitly does this when CART::Validate is in the same file. Now if that is module code is separated into a file of it's own then it'll work as expected when useed() as the import call did the job the first time thanks to Exporter code.

      Or have I totally misread the question, the error and the code presented?
      HTH

      _________
      broquaint

        The snippet he shows does not compile, and as such will not give that Undefined subroutine error, cause it will die at the use CART::Validate; line (Can't locate CART/Validate.pm in @INC).


        MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
        I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
        ** The Third rule of perl club is a statement of fact: pod is sexy.

Re: Re: Trouble Exporting a Function
by Rich36 (Chaplain) on Mar 13, 2003 at 18:27 UTC
    However you should really put everything below (and including) the line package CART::Validate into a file of it's own (i.e Cart/Validate.pm in one of the paths in @INC) and then your use statement will work fine.

    That's actually what I've done and what's causing me problems. The code for CART::Validate is in a separate file. Sorry for the confusion.


    «Rich36»