in reply to Re: Using require in a module and alongside that module in a program
in thread Using require in a module and alongside that module in a program

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

  • Comment on Re^2: Using require in a module and alongside that module in a program

Replies are listed 'Best First'.
Re^3: Using require in a module and alongside that module in a program
by kennethk (Abbot) on Aug 15, 2011 at 21:11 UTC
    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.