For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > January 2006 > Re: How to improve speed of returning value from calling method on an array of object









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: How to improve speed of returning value from calling method on an array of object
Adriano Ferreira

2006-01-10, 4:02 am

On 1/6/06, Sai Tong <stong@fidelio.rutgers.edu> wrote:
> I have an array of many objects and I want to call a method on
> each of these objects and the save the returned values into an array:


> my @return_values;
> foreach my $retrievedObject (@array_of_objects) {
> push (@return_values , $retrievedObject->method );
> }


Maybe you can use C<map>

my @return_values =3D map { $_->method } @array_of_objects;

But that's not going to be fast (as well as the for construction) if
the repeated calls of C<$_->method> aren't fast enough (for your
purposes).

Adriano.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com