in reply to Multiple references pointing to the same memory location

I suspect you can make the problem go away by fixing up your SQL. You're trying to retrieve records for an arbitrary list of ids, or something similar, right? If your database supports it, use IN (list) instead, and you can avoid the loop entirely. eg:

my @entries; my $idlist = join(',',map("'$_'",@keys)); my $sth = $dbh->prepare("SELECT * FROM mumble WHERE id IN($idlist)"); $sth->execute(); while (my $aref = $sth->fetchrow_arrayref()) { push(@entries,$aref); }

It's nice to learn why my 'push while fetch' constructions never worked, though.

update: if your @keys might contain anything more complicated than simple strings or numbers, it's better to use:

my $idlist = join(',',map($dbh->quote($_),@keys));

I think.

Replies are listed 'Best First'.
Re2: Multiple references pointing to the same memory location
by pmas (Hermit) on Jul 31, 2001 at 22:35 UTC
    Using IN(...)clause of SQL was exactly I wanted to propose when reading question on top - and it is already answered. ++ to you thpfft.

    Just small warning: different SQL dialects might have different limitations on how many items might go to IN(...) clause. So check your documentation and make sure you will tear your list and submit it to ->execute in chunks your SQL can handle, with smallest number of $sth->execute calls.
    And also be aware now you have piece of SQL code which is database-dependent. How bad it is depends of how many CGI scripts you have to manage. Maybe you want to put all SQL-dialect dependent snippets of code into separate module?

    pmas
    To make errors is human. But to make million errors per second, you need a computer.