--- Sergio Pires de Albuquerque <[EMAIL PROTECTED]> wrote:
I tried with our, importing that var and fully qualified it, but
always it get the previous value. My question is: Which method is common to
share data among apps? What Am I doing wrong? Also, I always use "strict" and "warnings".
You're talking about global variables and, in general, using them is a bad thing as it makes code more difficult to maintain. I won't go into that, though, as there's plenty of info elsewhere about that.
In your case, don't give access to the variables. If you're not going to go OO, give access to subroutines which can read and alter those variables.
package Foo; use strict; use warningsl
my $var = 7; sub var { $var } sub set_var { my $new_var = shift; unless (defined $new_var and $new_var =~ /^\d+$/) { require Carp; Carp::croak("Argument to set_var() can only be digits: ($var)); } $var = $new_var; } 1;
With techniques like that, you can at least ensure that there is one canonical place where the data is being fetched and altered. This gives you some measure of protection to ensure that naughty code isn't doing things it should not be doing and, if it ever gets set to a bad value, you have only one place to put your debugging code.
Cheers, Ovid
I agree with what Ovid said, but in the case where the data won't need or shouldn't be changed, you might consider using constants, which have a global nature but are considered less messy than global variables.
perldoc constant
Though I would still drop them into their own module that can be 'use'd. This works well for DB DSNs, base URLs, etc.
http://danconia.org
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>