On Oct 4, 2007, at 6:57 PM, Michael Barto wrote:
I am working with an old Perl Library (program module) written in
Perl4 and Perl 5 depending who was "hacking the code". My program
that calls it, uses -w and strict and has identified many syntax
errors and so forth in the old library which I fixed. My problem is
that this library needs two variables passed as globals to it to
use in one of the subroutines, One of them is the $dbh variable
created when the database is open. Another is a hash. Both these
variables were initiated at the Main top most level of the program
with "my". Unfortunately, this causes an error and the libraries
does not see the global.
My() isn't package scoped, it's file scoped.
Our() is package scoped, so add a package declaration at the top of
each of your files, and in each of them declare $dbh with our.
Basically, like this, at the top of each file that uses the shared
variable:
package SuperNifty;
our $dbh;
Alternatively, you could define $dbh in a module, and include it in
the module's @EXPORT or @EXPORT_OK, so that an alias to it is
exported into the module user's namespace.
sherm--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net