in reply to Re: Iterating over *any* thing in Perl
in thread Iterating over *any* thing in Perl

Some people use hashrefs or arrayrefs for their objects, and stuff all the attributes in the things the references point to (and those same people will vote '++' for if someone posts a coding guideline saying "Don't use global variables"). The advantage is that you can access the attributes all the time, from everywhere - the same advance as putting all your variables in main:: gives you.

What would you recommend should be done instead?

  • Comment on Re: Re: Iterating over *any* thing in Perl

Replies are listed 'Best First'.
Re^3: Iterating over *any* thing in Perl
by adrianh (Chancellor) on Dec 04, 2002 at 01:13 UTC

    Some options (in no particular order):

    • Use a proper OO language ;-)
    • Wait for Perl 6
    • Use inside out objects (for me, the neatest discovery from perlmonks so far - ++Abigail-II).
    • Hide your objects implementation behind a proxy object (Class::Delegation is handy for this sort of thing).
    • Document that you use a hash. Document the slot(s) that you use. One idiom that I've seen a few times is to do it as $object->{CLASS_NAME}->{SLOT_NAME}

    Any more for any more?