in reply to loading modules using sub
The solution is don't do this. Circular dependence can usually be replaced with simple inheritance with no loss of functionality. In this case, the 'solution' is to simply not have module A use B. More often, the easiest solution is abstracting the shared code into a common module 'C'.
#!/usr/bin/perl use lib "."; use A; use B; def(); ######################################## A.pm package A; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(abc); use C; ######################################## B.pm package B; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(def); use C; sub def{ print "Inside sub def of package B -> calling sub abc from package + C\n"; abc(); } ######################################## C.pm package C; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(abc); sub abc{ print "Inside sub abc of package A\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: loading modules using sub
by Anonymous Monk on Jun 25, 2010 at 06:21 UTC |