Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Mac > Perl on OSX > Re: "my variabl...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 5 Topic 997 of 1076
Post > Topic >>

Re: "my variable" at global level not being passed

by sherm@[EMAIL PROTECTED] (Sherm Pendley) Oct 4, 2007 at 10:06 PM

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 @[EMAIL PROTECTED]
 or @[EMAIL PROTECTED]
 so that an alias to it is  
ex****ted 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
 




 5 Posts in Topic:
"my variable" at global level not being passed
mbarto@[EMAIL PROTECTED]   2007-10-04 15:57:31 
Re: "my variable" at global level not being passed
bva@[EMAIL PROTECTED] (B  2007-10-04 16:19:33 
Re: "my variable" at global level not being passed
mbarto@[EMAIL PROTECTED]   2007-10-04 18:56:53 
Re: "my variable" at global level not being passed
sherm@[EMAIL PROTECTED]   2007-10-04 22:06:56 
Re: "my variable" at global level not being passed
jeremiah@[EMAIL PROTECTED  2007-10-05 12:54:20 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Dec 5 0:41:29 CST 2008.