Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Re: Iterating over *any* thing in Perl

by jryan (Vicar)
on Dec 03, 2002 at 19:19 UTC ( #217318=note: print w/replies, xml ) Need Help??

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?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://217318]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2021-05-11 16:41 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (119 votes). Check out past polls.