in reply to Efficiency on Code

I assume that last line should be push @array_claim, $TOALL?

If you are trying to do what I think you are (create an array containing all the 'ACCOUNT#' values from a query), try this:

## This assumes your select begins 'SELECT [ACCOUNT#]', ## that is, ACCOUNT# is the first column returned @array_claim = map { $$_[0] } @{$sth->fetchall_arrayref};

Read up on map to understand how that works.

FYI, fetchrow_hashref is the slowest of the fetchrow_ methods, so you want to avoid it unless you have no better choice.

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

Replies are listed 'Best First'.
Re^2: Efficiency on Code
by Anonymous Monk on Jan 06, 2005 at 19:11 UTC
    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

      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.

      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