in reply to Re: Calling a sub in a Module
in thread Calling a sub in a Module

# Code where sub is defined: use Exporter(); my @ISA = qw/Exporter/; my @EXPORT = qw/&getData/; sub getData { # do stuff # return a hash } # Package declarations - none, that I'm aware of. Never # had this problem before, using &Reader::getData and the # like. # Failing call: use Book::Reader; my $hashref = &Book::Reader::getData;

Replies are listed 'Best First'.
Re: Re: Re: Calling a sub in a Module
by broquaint (Abbot) on Oct 23, 2002 at 09:49 UTC
    Package declarations - none
    You need a package declaration of Book::Reader otherwise getData() will live in the main package. Also if you want to export methods in the current package you don't need to put an ampersand (&) before the name1, and @ISA and @EXPORT need to be package level variables e.g
    package Book::Reader; require Exporter; @ISA = qw( Exporter ); @EXPORT = qw( getData ); use strict; sub getData { ... }

    HTH

    _________
    broquaint

    1 as chromatic notes in his node Exporter will treat &sub the same as sub in the @EXPORT list

      Also if you want to export methods in the current package you don't put an ampersand (&) before the name

      Are you sure? Exporter would seem to disagree.

Re: Re: Re: Calling a sub in a Module
by lestrrat (Deacon) on Oct 23, 2002 at 09:50 UTC

    Two things: if that is exactly what your code says, then you're missing a package declaration. Also you can't use my there. Should be our

    package Book::Reader; use strict; use Exporter; our @ISA = qw/ Exporter /; our @EXPORT = qw/ getData /; ....

    Incidentally, the Expoter bit doesn't mean anything if you are calling your sub with a fully qualified name like Book::Reader::getData(), so if you don't need to export it, you should get rid of those lines...

      Cool, that's soted it. Cheers for the help. :)