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

Is there any way to ignore namespace changes that will occur in a procedure before calling the procedure? :)

Details: I have several databases that have a field count in the fifty+ range. I got tired of copying/pasting the variable names to read in from the array (DBI), so I threw the variable stuff into a function, and made it a library that I "required." Simple stuff.

Problem: I'm adding a feature to a rather large script (6000 lines), and I'm using a particular library I wrote. This library calls the variable library, but this causes a conflict with the variables in my main script...

"Change the variable names" would of course work, but then I would have to change much printed and unprinted documentation.... that and its the easy way out.

There are about twenty different programs now using those libraries, and I'd prefer solutions that didn't require modifying the calling programs... anybody have any ideas?

If I'm not being clear feel free to yell at me to post examples. Thank You.

  • Comment on Not changing current namespace with a library

Replies are listed 'Best First'.
(tye)Re: Not changing current namespace with a library
by tye (Sage) on Jan 19, 2001 at 04:44 UTC

    Instead, change your package to export a bunch of variables to whatever package you are currently using:

    package My::DataBase::Variables; use base qw(Exporter); use vars qw( @EXPORT ); BEGIN { @EXPORT= qw( $this $that $theOther long list of variables ); } use vars @EXPORT;
    then
    use My::DataBase::Variables; print "$this is not $that nor $theOther\n";
    You can export these variables to any number of packages and change a value via one package and that value will be seen by the other packages.

            - tye (but my friends call me "Tye")