CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Re: [angshuman] loading using 'use': Edit Log



FishMonger
Veteran / Moderator

Jun 25, 2010, 6:43 AM


Views: 1328
Re: [angshuman] loading using 'use'

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

Code
1;


Here's the updated/corrected version.

abc.pl

Code
#!/usr/bin/perl 

use strict;
use warnings;
use lib ".";
use B;

def();


A.pm

Code
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

Code
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)


Edit Log:
Post edited by FishMonger (Veteran) on Jun 25, 2010, 6:44 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives