ribonuceloside has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I'm fairly new to perl and wondering if I could ask a little assistance in making my script work. I've got an array full of 7 character codes and this is my attempt to have the first three codes equivalent database entries be returned in .html format. It works fine when I'm having the sth->fetchrow_array assign to an array, but now I've used a hash the counter I've set has gone bonkers and it isn't behaving the way I thought it would and I really can't see why. My intended out put is as follows
<tr> <td>AccNo</td> <td>$result[0]</td> </tr> <tr> <td>GeneLocus</td> <td>data</td> </tr> <tr> <td>aaSequence</td> <td>data</td> </tr> <tr> <td>AccNo</td> <td>$result[1]</td> </tr> <tr> <td>GeneLocus</td> <td>data</td> </tr> <tr> <td>aaSequence</td> <td>data</td> </tr> <tr> <td>AccNo</td> <td>$result[2]</td> </tr> <tr> <td>GeneLocus</td> <td>data</td> </tr> <tr> <td>aaSequence</td> <td>data</td> </tr>
When I change the counter, it changes the number of rows, rather the number of sets of rows printed. I'm baffled. Thanks very much for your help in advance
$i=0; my %germline; my @key = ('AccNo', 'GeneLocus', 'aaSequence'); # get top 3 fasta-result-hit rows from germline dB until($i==3){ my $sql = "SELECT DISTINCT AccNo, GeneLocus, aaSequence FROM aaSEQ + a, Ig_functional b WHERE a.aaID = b.RecNo AND AccNo = '$result[$i]';"; my $sth = $dbh->prepare($sql) or die "Could not prepare statement: + " . $dbh->errstr; if ($sth->execute){ while (($germline{AccNo}, $germline{GeneLocus}, $germline{aaSe +quence}) = $sth->fetchrow_array){ print "<tr>\n<td>$key[$i]</td>\n<td>$germline{$key[$i]}</t +d>\n</tr>\n\n"; } } $i++; } $dbh->disconnect();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Looping loops
by Anonymous Monk on Aug 08, 2013 at 23:25 UTC | |
by ribonuceloside (Initiate) on Aug 09, 2013 at 09:14 UTC |