--- 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

-- 
If this message is a response to a question on a mailing list, please send
follow up questions to the list.

Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to