shemp has asked for the wisdom of the Perl Monks concerning the following question:
Then, in another method, i need to operate on each element of the big list. I could write a method called GetBigList, and methods that want to operate on the list could access each element by looping through the return results of GetBigList()$self->{'Big_List'} = [many elements];
... and encapsulation is happy.sub GetBigList { my $self = shift; return $self->{'BigList'}; } sub SomeOperation { my $self = shift; foreach my $element ( @{$self->GetBigList()} ) { # do stuff to element, etc. } }
And i have broken encapsulation, but my scripts should incur much less overhead.sub SomeOperation { my $self = shift; foreach my $element ( @{ $self->{'Big_List'} } ) { # do stuff to element, etc. } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array copy or encapsulation break?
by Aristotle (Chancellor) on Aug 06, 2003 at 16:56 UTC | |
by shemp (Deacon) on Aug 06, 2003 at 17:01 UTC | |
by dragonchild (Archbishop) on Aug 06, 2003 at 17:08 UTC | |
|
Re: Array copy or encapsulation break?
by adrianh (Chancellor) on Aug 06, 2003 at 17:02 UTC | |
|
Re: Array copy or encapsulation break?
by broquaint (Abbot) on Aug 06, 2003 at 17:01 UTC | |
|
Re: Array copy or encapsulation break?
by shemp (Deacon) on Aug 06, 2003 at 17:09 UTC | |
by BrowserUk (Patriarch) on Aug 06, 2003 at 21:41 UTC |