[prog] Member variables in Perl

Kathryn Andersen kat_lists at katspace.com
Thu Jun 12 20:11:05 EST 2003


On Thu, Jun 12, 2003 at 10:47:09AM +0200, Dan Richter wrote:
> Perl has the peculiarity of implementing each object as a hash, with its 
> member variable names as keys and the values as values. (Sure, you don't 
> HAVE to do it that way - There Is More Than One Way To Do It [TIMTOWDY] - 
> but in most cases it's the only sane way.)
> 
> This introduces the possibility of collisions between parent class and 
> subclass data. Are there any generally accepted ways of avoiding such 
> collisions?

Well, one convention to at least reduce the collisions between data
that's used internally in the object, and data that might be exported,
is to prefix the keys of internal data with "_".

But that doesn't answer your question, really.  Trying to avoid using
generic names is one idea.  Another is, well, perl objects are really
more like "grey" boxes than "black" boxes -- you may have to look inside
the box.

If you are really worried about it, and don't want to look inside the
box, you could always prefix your keys with "_${subclass_name}_"

Kathryn Andersen
-=-=-=-=-=-=-=-=-
Jenna:      Where are you taking her?
Vila:       Does it matter? Can't be any worse than here.
Cally:      Unless she's going to die.
				(Blake's 7: Horizon [B4])
-- 
 _--_|\	    | Kathryn Andersen	<http://www.katspace.com>
/      \    | 
\_.--.*/    | GenFicCrit mailing list <http://www.katspace.com/gen_fic_crit/>
      v	    | 
------------| Melbourne -> Victoria -> Australia -> Southern Hemisphere
Maranatha!  |	-> Earth -> Sol -> Milky Way Galaxy -> Universe


More information about the Programming mailing list