in reply to Re: predeclaring subs problems
in thread predeclaring subs problems

Maybe I can ask this another way. Here is my module:
package Module; use strict; use Exporter; use vars qw{$VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS}; $VERSION = '0.01'; @ISA = qw(Exporter); @EXPORT = qw(); @EXPORT_OK = qw(food cook); %EXPORT_TAGS = ( kitchen => [qw(food)], all => [qw(food cook)]); sub cook; sub food; cook { print "cooked $_[0]"; } food { my $food = $_[0]; defined $food or $food = 'apples'; print "$food is food"; } 1;

My script using this module..

use Module qw(:all); food('grapes'); food; # this works fine.

However, when I have another module, that also has

use Module qw(:all);
i get an error!
Undefined subroutine &Module::Module2::div called at /xxxxx/Module/Mod +ule2.pm line xxx

I read that predeclaring a sub is what allows me to gove it arguments such as  food 'orange'; - This is making me a little loopy.

I think what's going on here, since use runs once, the main script is immporting &food - an therefore any other modules that may want to call &food, will have to do so as &::food .. is that correct? How do I get &food to be inherited by all the code ? I guess is what i want..

Replies are listed 'Best First'.
Re^3: predeclaring subs problems
by ikegami (Patriarch) on Mar 20, 2006 at 15:36 UTC

    First, don't post code you didn't run. You're missing the word "sub" in a couple of places.

    Secondly, since the error is in Module2, it would help if you could show it.

    I suspect you did

    use Module qw(:all); package Module2; ... cook(); ...
    when you should have done
    package Module2; use Module qw(:all); ... cook(); ...
    The former imports everything into the wrong package.