John W. Krahn wrote:
> 
> Yes, Perl uses references which are conceptually similar to pointers.
> 
>         my $users = get_all_users();
>         for ( my $i = 0; $i < @$users; ++$i ) {
>                 my $details = get_user_details( $users->[ $i ] );
>                 my $sum   = 0;
>                 my $count = 0;
>                 for ( my $j = 1; $j < @$details; $j += 2 ) {
>                         $sum += $details->[ $j ];
>                         $count++;
>                 }
>                 $means{ $user } = $sum / $count;

That should be:

                 $means{ $users->[ $i ] } = $sum / $count;


>         }
> 
> Although in my tests that takes about the same time to execute but uses a
> *lot* less memory as it doesn't have to make a copy of the @$users array like
> your version does.



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to