
FishMonger
Veteran
Jun 25, 2010, 6:43 AM
Post #3 of 5
(585 views)
|
|
Re: [angshuman] loading using 'use'
[In reply to]
|
Can't Post
|
|
Please use the code tags when posting your code. Unfortunately, I don't recall the "under the hood" details on how perl loads modules, but the order that you "use" them can/will alter how and when they are loaded/inherited. abc.pl never calls the sub that is defined in A.pm, so there's no reason to "use" it in that script. Likewise, A.pm doesn't call anything from B.pm, so there's no reason to for A.pm to "use B;". All Perl scripts and modules should use the strict and warnings pragmas and all vars need to be declared with either the my or our keyword depending on its required scope. Modules should always end with a true statement. i.e. the last line should be Here's the updated/corrected version. abc.pl
#!/usr/bin/perl use strict; use warnings; use lib "."; use B; def(); A.pm
package A; use strict; use warnings; use Exporter; our @ISA = qw( Exporter ); our @EXPORT = qw( &abc ); sub abc{ print "Inside sub abc of package A\n"; } 1; B.pm
package B; use strict; use warnings; use Exporter; use A; our @ISA = qw( Exporter ); our @EXPORT = qw( &def ); sub def{ print "Inside sub def of package B -> calling sub abc from package A\n"; abc(); } 1;
(This post was edited by FishMonger on Jun 25, 2010, 6:44 AM)
|