in reply to Redefined subroutines in multiple libraries

Having a circular dependency like this is generally a sign of tight coupling, which is a bad thing. Other people have suggested that you create modules. That is just a way to repackage the problem so it shows up in a different way. See my reply to ikegami for an explanation of how it shows up if you do that.

The safe solution is to move one require inside of a function call. So, for instance, move the require of libB.pl into subroutine A. This is only going to actually load the other library once, so don't worry about performance. For an example of this in the Perl core, Carp needs to use Exporter to export functions, and Exporter uses Carp to report problems. In that case Carp is loaded on demand from within Exporter.

This solves the real problem, but does nothing about your fairly harmless warning. To remove your warning you merely need to write a script that requires one of the libraries rather than run the libraries as programs in their own right.

(Random tip. Renaming libA.pl to libA.pm and putting a package statement in it is a very easy change to make, and brings all sorts of side benefits. You can use Exporter to export functions, and as a bonus it will be easier when debugging to figure out which functions came from where.)

  • Comment on Re: Redefined subroutines in multiple libraries