Perl: the Markov chain saw | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Indeed. One way of avoiding this is to use your own package name in the hash key, to ensure a little more uniqueness:
This technique can only get you so far though - with some classes it's not enough, so the inside-out object technique explained by JavaFan is necessary. As an example, imagine an EmailHeaders class where each hash key represents an e-mail header (To, From, Subject, etc). You want to subclass it and store some additional information which is not an e-mail header. But any key you add to the hash will be interpreted as another e-mail header by the parent class. Here you really would need to use inside-out objects.
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
In reply to Re: avoiding overwriting variables in an inherited class
by tobyink
|
|