in reply to Re^2: Redefined subroutines in multiple libraries
in thread Redefined subroutines in multiple libraries

Don't execute modules as scripts.
perl -e"use MySub1"
will be clean.

Replies are listed 'Best First'.
Re^4: Redefined subroutines in multiple libraries
by tilly (Archbishop) on Jan 10, 2009 at 00:02 UTC
    A note on why this happens. When Perl goes to load a module, it first checks whether it has ever started to load that module and then skips it if it has. So in your use example when you use MySub1 it marks that off, and decides to load MySub2. When it loads MySub2 it realizes it needs to load MySub1, but realize it started that already, and so skips it. It then loads the rest of MySub2, then loads the rest of MySub1 and continues.

    So there is no re-definition warning because you do not try compiling MySub1 twice. But the lack of the warning does not mean that things are necessarily OK. There are nasty lurking potential problems around the fact that when MySub2 completes it expects MySub1 to be there and it isn't. So if, for instance, MySub1's import method has not been created at the point in time where MySub2 is encountered, then that import will not happen. And this failure to run the not yet defined import will be silent! The resulting errors can be extremely mysterious.

    Unless you know exactly what you are doing here, and why, here be dragons.