Connie Chan wrote:

> Thanks everybody, I've learn quite a lot in this lesson again.
> Anyway, I still not up the OO level in Perl, so, quite sort of
> information here I still need sometime to digest.
> 
> Here is something I've simply test, but not confirm they are
> right or not.
> 
> When I pick up an exported vars from a package, is it becomes a
> gobal var?

it becomes a global variable in a sense that you don't have to prefix the 
variable with which package it belongs too. all varaibles(even the default 
one like @INC, @ISA etc) belong to a package. if no package is specified, 
the package "main" is defauled. you can verify this a bit by:

#!/usr/bin/perl -w
use strict;

foreach(keys %::){
        print "$_ $::{$_}\n";
}

...
IO:: *main::IO::
ENV *main::ENV
strict:: *main::strict::
... etc

as you can see, all variables have *main:: in front of them.

>When I modify the vars value, is that other package
>will share the same value too?

yes. since all varable belong to a package, whenever you modify it, it's new 
value reflects in it's package's sample table. when you access that 
variable from another package, you are still accessing the variable in it's 
package's sample table so the value appears to be shared.

> 
> Base on my test, they are both yes. But any exception ?
> 
> Here is an idea for how I will play with a this kind of value.
> Would anybody comment on it ?
> 
> ######
> package myglobal;
> use strict;
> 
> require Exporter;
> our @ISA = qw (Exporter);
> our @EXPORT = qw (%VARS RELOAD_VARS);
> our %VARS;
> 
> sub RELOAD_VARS
> {
>     $VARS{A} = 'A';
>     $VARS{B} = 'B';
>     $VARS{C} = 'C';
> }
> 
> RELOAD_VARS unless keys(%VARS);
> 1;
> #######
> 
> Say, some packages, whatever A,B,C,D,E will use %VARS,
> and base on some simple test, they are able to retrieve
> %VARS and its modified values, and I can reload it anytime
> I want. But, again, I am not sure what I am doing is right
> or wrong, perhaps there are some special cases that I can't
> imagine right now. Anybody can help me to confirm this?
> 
> Rgds,
> Connie


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to