in reply to Storing Info with Accessors

It seems to me you could avoid a lot of this by writing an Autoload method that handles your accessor problems. A standard one (lifted from Damian Conway's Awesome "Object Oriented Perl") looks like:
sub AUTOLOAD { my ($self,$newval) = @_; if ($AUTOLOAD =~ /.*::get_(\w+)/){ return $self->{$1}; }elsif($AUTOLOAD =~ /.*::set_(\w+)/){ $self->{$1} = $newval; }else{ croak "$AUTOLOAD is not a method"; } }
You could then just call something like my $value = $object->get_items_in_order(); and avoid a begin block and the overhead of eval'ing altogether. With some minor modifications, the Autoload could deal with your array reference problems I think (unless I misunderstood).

Replies are listed 'Best First'.
Re: Re: Storing Info with Accessors
by graq (Curate) on Aug 02, 2001 at 12:37 UTC
    Interesting. That looks extremely useful and much better than my original code (and got a significant ++ing)

    Do you know of any differences between the two (my original and your suggestion) in behaviour, performance, problems, restritions? Any conditions under which my original code is 'better' than your suggestion?

    Or is your suggestion exactly what it looks like - much better all round :) ?

    --
    Graq