in reply to Re: Efficiency on Code
in thread Efficiency on Code

Hi,
This is what I have, and when I run the code it is very slow. And it is only slow when the code inside the while loop runs if I commented out the while loop the code is very fast.
Here is what I have:
while ( @array_c = $sth->fetchrow()){ $TOALL = &cleaner ($pointer->{'ACCOUNT#'}); push @array_c,$TOALL; # Array that has all account numbers } print "<br><font color=red><b> $array_c </b></font>";

After that I have to use the values there from the @array_c to do another DB query
Thanks

Replies are listed 'Best First'.
Re^3: Efficiency on Code
by nedals (Deacon) on Jan 06, 2005 at 19:37 UTC

    After that I have to use the values there from the @array_c to do another DB query

    In addition to the previous comments..
    Can you combine that second (looped) DB query into the first query?
    That will considerably reduce the overall time since there will be fewer calls to the DB.

Re^3: Efficiency on Code
by legato (Monk) on Jan 06, 2005 at 21:24 UTC

    That code doesn't make sense. You are attempting to invoke fetchrow() and store its result in @array_c. Then you try to dereference $pointer, which you have not set.

    My suggestion stands. Change the number of the index in my original code to match the position at which your 'ACCOUNT#' field is returned, or find that by doing:

    my $index = map { next unless $_ eq 'ACCOUNT#'; $_ } @{$sth->{NAME}}; ##Now, my original code: @array_c = map { $$_[$index] } @{$sth->fetchall_arrayref()};

    Anima Legato
    .oO all things connect through the motion of the mind