Robin Sheat wrote:
> On Thursday 12 October 2006 23:52, John W. Krahn wrote:
>> 
>>        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;
>>        }
>>
>> 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.
> 
> I don't follow. Where was my version copying @$users?

I screwed up the test I tried :( so I might be wrong, although in older
versions of Perl using:

        foreach my $user (@$users) {

would create a copy of @$users to a list in memory, but it appears to be OK
with the version of Perl I am currently using.  :-)



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