in reply to Re: predeclaring subs problems
in thread predeclaring subs problems
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
i get an error!use Module qw(:all);
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 |