CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced: Problem with fetchrow_array: Edit Log



kwatts59
Novice

Jun 23, 2017, 1:08 PM


Views: 30526
Problem with fetchrow_array

Hello all,
I am having problems with fetchrow_array.
It prints all the gene symbols and runs fine until the last record, then it fails.
Below is the code:


Code
$sql_cmd = "select gene_symbol,refseq_id from gene_symbols where gene_symbol is not null"; 
my $sqlquery = $dbh->prepare($sql_cmd) or die "Cannot prepare query \n";
my $rv1 = $sqlquery->execute or die "Cannot execute query $sql_cmd\n";
my @row = $sqlquery->fetchrow_array or die "Cannot fetch $sql_cmd\n";
my $i = 0;
while (defined $row[0])
{
$i++;
$gene_symbols[$i] = $row[0];
print "$i\t$row[0]\n";
@row = $sqlquery->fetchrow_array or die "Cannot fetch $sql_cmd\n";
}
print "Loaded $i gene symbols\n";
$TOTAL_GENES= $i;


When it gets to the last row in the query, it just fails with "Cannot fetch select gene_symbol,refseq_id from gene_symbols where gene_symbol is not null"

It doesn't exit the loop and it doesn't get to the print command "Loaded xxx gene symbols" at the end of the while loop.

Any help would be appreciated.
Thanks in advance.
Ken


(This post was edited by kwatts59 on Jun 23, 2017, 1:10 PM)


Edit Log:
Post edited by kwatts59 (Novice) on Jun 23, 2017, 1:10 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives