leocharre has asked for the wisdom of the Perl Monks concerning the following question:
a.pm:
package A; use vars qw{$VERSION @ISA @EXPORT @EXPORT_OK}; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(&a); use strict; sub a; sub a { $a = $_[0]; defined $a or $a='a'; print $a; } 1;
The following use of A.pm works fine. script.cgi
#!/usr/bin/perl -Tw use lib 'where/a/pm/resides'; use strict; use A; a; exit;
However, if I add another module that uses A.pm's b subroutine..
B.pm:
package B; use vars qw{$VERSION @ISA @EXPORT @EXPORT_OK}; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(&b); use strict; use A; sub b; sub b { a; } 1;
And make use of this...
script2.cgi
#!/usr/bin/perl -Tw use lib 'where/a/pm/resides'; use strict; use A; use B; a; b; exit;
I get an error on b.. that it's a bareword. But- why? I can turn the call as &b; and it will work, but.. why didn't a need that ? I tried doing use A on B.pm, but it makes no diff- I am so missing something here. What is it?
I read that if you predeclare a sub then you don't need to use () to pass args, do I need to predeclare a sub somewhere else ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: predeclaring subs problems
by ikegami (Patriarch) on Mar 17, 2006 at 20:49 UTC | |
by leocharre (Priest) on Mar 19, 2006 at 20:44 UTC | |
by ikegami (Patriarch) on Mar 20, 2006 at 15:36 UTC |