J
jh3an
Please give me your advice 
I was reading perltoot document, and I got stuck the following class
global variable concept.
HELP!!
Why global variable should be accessed by hash like this? :
$self->{"_CENSUS"}
Perltoot doc:
Accessing Class Data
It turns out that this is not really a good way to go about handling
class data. A good scalable rule is that you must never reference
class data directly from an object method. Otherwise you aren't
building a scalable, inheritable class. The object must be the
rendezvous point for all operations, especially from an object method.
The globals (class data) would in some sense be in the "wrong" package
in your derived classes. In Perl, methods execute in the context of
the class they were defined in, not that of the object that triggered
them. Therefore, namespace visibility of package globals in methods is
unrelated to inheritance.(WHAT THE HECK HE IS TALKING ABOUT @.@??????)
Got that? Maybe not. Ok, let's say that some other class
"borrowed" (well, inherited) the DESTROY method as it was defined
above. When those objects are destroyed, the original $Census variable
will be altered, not the one in the new class's package namespace.
Perhaps this is what you want, but probably it isn't.
(WHAT THE HECK HE IS TALKING ABOUT @.@??????)
I was reading perltoot document, and I got stuck the following class
global variable concept.
HELP!!
Why global variable should be accessed by hash like this? :
$self->{"_CENSUS"}
Perltoot doc:
Accessing Class Data
It turns out that this is not really a good way to go about handling
class data. A good scalable rule is that you must never reference
class data directly from an object method. Otherwise you aren't
building a scalable, inheritable class. The object must be the
rendezvous point for all operations, especially from an object method.
The globals (class data) would in some sense be in the "wrong" package
in your derived classes. In Perl, methods execute in the context of
the class they were defined in, not that of the object that triggered
them. Therefore, namespace visibility of package globals in methods is
unrelated to inheritance.(WHAT THE HECK HE IS TALKING ABOUT @.@??????)
Got that? Maybe not. Ok, let's say that some other class
"borrowed" (well, inherited) the DESTROY method as it was defined
above. When those objects are destroyed, the original $Census variable
will be altered, not the one in the new class's package namespace.
Perhaps this is what you want, but probably it isn't.
(WHAT THE HECK HE IS TALKING ABOUT @.@??????)