http://qs321.pair.com?node_id=310011


in reply to Re: Re: Re: Why get() and set() accessor methods are evil
in thread Why get() and set() accessor methods are evil

So why couldn't/wouldn't you do the exact same in perl? You could even do it transparently via tie, or you could do it overtly by creating the object. Seems fairly simple to me at least.
package ArrayList; my $i; sub new{shift;return bless{[@_]=>shift};} sub iterate{return $_[0]->[$i++]}
And so on and so forth.

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Why get() and set() accessor methods are evil
by hardburn (Abbot) on Nov 25, 2003 at 18:57 UTC

    One reason you wouldn't want to is that is Perl's context-sensitivity. By using ArrayList, which would be implemented as a scalar holding a referance, you're now putting things in scalar context that really should be in list context.

    BTW--Check out the Class::Iterator module for doing this.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    : () { :|:& };:

    Note: All code is untested, unless otherwise stated