Re: How to improve speed of returning value from calling method on an array of objects?



On 1/6/06, Sai Tong <stong@xxxxxxxxxxxxxxxxxxx> 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 = 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.
.



Relevant Pages

  • finding maximum element in an array recursively
    ... can someone show me other ways to find the max. element in an array ... purposes). ... sub max { ... Prev by Date: ...
    (comp.lang.perl.misc)
  • Re: conditional formatting autoshapes
    ... I have manipulated the code for my purposes, ... am coming up with "cant assign to array" at the following line in the ... Prev by Date: ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Looking for speed performance to draw line.
    ... each item in an array, that being the next and/or previous indexes. ... and it's next pointer to the previous item's original next pointer. ... Next -1, Prev 0 ... shapes up into shape classes that implemented the required commands ...
    (microsoft.public.vb.winapi.graphics)
  • Re: memory allocation question
    ... it as an array it is quite flexible. ... For the purposes of pointer math, ... In some contexts, such as yours above. ...
    (comp.lang.c)
  • Re: Fast image processing in C#
    ... but fast enough for my purposes. ... using LockBits and Marshal.Copy to copy the image data into an array, ... you'll have to look at every pixel whether it's in an array or not. ...
    (microsoft.public.dotnet.languages.csharp)