in reply to Using require in a module and alongside that module in a program

First off, as it appears you are just using subs.pl as an import/export mechanism, you really should follow Tanktalus's advice and use Exporter. Since you desire to export from subs.pl into both Modis::ParseMe and main, you might consider modifying ParseMe.pm to optionally export the desired subroutines.

If this is a get-it-done moment and not for the long term, you can make the import happen with do instead of require. require 'file'; is essentially do 'file' or die "Can't locate file in \@INC"; with some extra overhead to make it happen only once.

Replies are listed 'Best First'.
Re^2: Using require in a module and alongside that module in a program
by alextor (Novice) on Aug 15, 2011 at 15:36 UTC

    Thanks for the replies, I'll try to get Tanktalus's method implemented.

    If in the main program I use 'do' on the file instead of 'require', does it take that library away from Modis::ParseMe?

    Thanks

      If you use do, you literally execute the contents of the file in your current context, very similar to a straight in-lining. The interpreter will have no knowledge that the subroutines in your main program and in your Modis::ParseMe module should be related - you will essentially be using two identical, independent libraries.

      There are a number of drawbacks to this approach; for example, if your subs from subs.pl use closures, there will be no relationship between the variables wrapped in main and in Modis::ParseMe. Thus, if you are talking about a long term solution, you want use an Exporter.