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

Dear monks.

I've written a large procedure with userspecific code and want to swap out this parts for afterwards inclusion.

If I declare new packagenames for those code and load it with a
do 'part1_code'
, I must declare the common used variables with
local $packagename::varname in this procedure.

Is there another way to declare 'my' -vars and use the swaped out code without addition packagedefinition?

Many tanks in advance.
Andreas

Replies are listed 'Best First'.
Re: namespaces and source out
by perrin (Chancellor) on Feb 11, 2003 at 15:28 UTC
    The right way to do it is to make them packages, and pass variables to the subroutines instead of relying on globals.
    package Foo; print Bar::hello('world'); package Bar; sub hello { my $who = shift; return "hello $who"; } 1;