in reply to Re: Re: (tye)Re: Reference as the only Object element
in thread Reference as the only Object element

After chatting with Fatvamp, I think what he wants is something close to this:

sub new { return bless [], shift; } sub addItems { my $self= shift; unshift @$self, @_; } sub setList { my $self= shift; my( $ref )= @_; if( 1 == @_ && ref($ref) ) { @$self= @$ref; } else { @$self= @_; } } sub getItem { my $self= shift; my $idx= shift; return $self->[$idx]; } sub getList { my $self= shift; if (wantarray) { return @$self; } else { return [@$self]; } }

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: (tye)Re2: Reference as the only Object element
by dragonchild (Archbishop) on Nov 02, 2001 at 23:22 UTC
    Basically, he wants some class that acts as an array. That works just fine.

    I'd make one reccomendation - be positive that addItem() is always going to do an unshift. It's more intuitive to add to the end vs. the beginning of a list.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.