Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: Structure of a custom class (using Apache::Session)by Akhasha (Scribe) |
on Jun 16, 2005 at 01:19 UTC ( [id://467128]=note: print w/replies, xml ) | Need Help?? |
As for using a hash as a backing store but only using 1 key, its only a little wasteful if there are never more than one of these objects around, and its flexible when/if you ever need to add more fields/properties. Its a little more efficient to make $self a blessed reference to an array. I'm not sure about blessing a reference to your tied hash but you could try it. I tend to think that would be dangerous as the creation of your backing store is then out of your hands, or at least not where a reader might expect it to be. If you're sure you'll never need more than one field in your class, you can bless a reference to a scalar. That scalar can in turn be a reference to your tied hash. It seems a little silly if there aren't many of these objects, but probably is a little more efficient than having a hash with one key.
In Section
Seekers of Perl Wisdom
|
|