Some things to consider:
- If @compile has several items with the same value, then you have a duplicate.
- if $identifier is duplicate in your table, then it is printed more than once.
- You have @version in your query, but it does not seem to be declared. Moreover, @version is an array. Are you sure you want to use an array as a single value? Should it be $version instead?
- "SELECT *" will get all the fields, without a guarantee of a particular order. Then your $identifier will get the first column in
your result set, whichever it is. If you need only one column, name it in your SELECT.
- Perl has several ways of quoting strings. Using qq{}, qq(), qq[],qq<> will let you use double quotes as literals inside
your string.
- Better yet, use $dbh->quote to quote your variables before merging them in a query string.
- Even better yet, use placeholders. See below for an example and DBI Recipes for a wider explanation.
- The error string for DBI comes with $DBI::errstr, not "DBI:: error"
Here is an (untested) rewrite of your code.
Make sure you understand what is there. See our Tutorials page for more basics on database programming with Perl.
my @compile=param ('compile');
my $version = "whatever";
my $dbh=DBI->connect($dsn,$user,$password,)
or die "Error $DBI::errstr connecting to $dsn";
my $sth=$dbh->prepare(qq{
SELECT
mycolumn
FROM
ddts
WHERE
`Stat`= ?
AND `Project`= ?
AND `Version`= ?
});
$sth->execute("T", "Def", $version);
print "<table border=2>";
while (my ($identifier) = $sth->fetchrow_array ) {
foreach my $elem (@compile) {
if ($elem eq $identifier) {
print "<tr><td>$identifier</td></tr>";
}
}
}
print "</table>";
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.