in reply to Array copy or encapsulation break?
Two alternatives spring to mind.
Rather than returning the list with GetBigList() return an iterator. So you would apply an operation something like:
my $i = $foo->get_big_list; while (my $element = $i->next) { # do stuff to $element };
Alternatively, have a routine in your class that takes an anonymous subroutine and applies it to each element.
# in your class sub apply_to_elements { my ($self, $coderef) = @_; $coderef->($_) foreach @{ $self->{'Big_List'} }; }; # somewhere else $foo->apply_to_elements( sub { my $element = shift; # do stuff to $element } );
|
|---|