In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (3li Marion) writes: >I encounter a very strange problem with interactions between main program >and several modules. > >If there is no interaction between modules (module1 calling module2 and >module2 calling module1) there is no problem with any sub each module. > >But if the mod1 uses 'use mod2' and mod2 uses 'use mod1' then mod2 can't >find any sub of mod1.
This is a known issue. Google with appropriate terms and you will find discussion about it on perl5-porters. While it is true that it is often due to a design that could be improved, I don't think that's always the case. Anyway, understanding why it happens may help you come up with a solution. During compilation, when perl comes across a 'use' statement, it immediately loads and compiles the module denoted. So if module A uses module B, at the point perl sees "use B", it starts compiling B. Now when compiling B, if perl sees a "use A", it won't actually do anything because the moment it thinks it's already compiled A, when in fact it's actually only partly done. The entry in the %INC hash is what tells perl this, and if you delete it at the wrong point during compilation you can get yourself into a lot of trouble :-) So subroutines in A that are defined after the "use B" won't have been compiled by the time B is compiled, and a "use A" statement in B won't help. Solution: hoist the subroutine definitions that B needs from A up above the "use B" statement, or predeclare them with stubs. -- Peter Scott http://www.perldebugged.com/ *** NEW *** http://www.perlmedic.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
