blahblah has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I'm writing a program that slurps in other bunches of perl code using require. These other bunches of perl code may contain subroutine names that already exist in the main:: program's namespace. I don't want collisions or subroutine re-definitions. How do I isolate the subroutines from the slurped code into their own namespace? Is there a way to do it without packaging the slurped code as modules? Finally, as long as I'm at it, I probably want to isolate all of the arrays, hashes, and variables to the same namespace from whence they came as well. Thanks, alex
  • Comment on isolating slurped-in code to a namespace

Replies are listed 'Best First'.
Re: isolating slurped-in code to a namespace
by Biker (Priest) on May 21, 2002 at 20:29 UTC

    In your main file, add a package from where you do nothing than to slurp in that external code. The external code will then be part of this package, which is not the Main package.


    Everything went worng, just as foreseen.

Re: isolating slurped-in code to a namespace
by Juerd (Abbot) on May 21, 2002 at 22:05 UTC

    Creating modules might be easier.

    From your story, I guess the files don't have package declarations. To wrap them in packages, try:

    { package Foo; require 'bar.pl'; }

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.