This sequence of statements can be easier:
$query = "select * from finalLevel3 where id=\"$ID\";"; $sth = $dbh -> prepare($query); # I would suggest this: my $query = $dbh->prepare("SELECT * FROM finalLevel3 WHERE id='$ID'");

I personally like to captialize the SQL key words, but preferences vary. Also the single quote within the double quote will expand $ID just fine. There is no need for \" in this situation. I was amazed when I learned this.

I am also a bit confused about this:

foreach $item (@{$clusters}) { #..... }

I would think that since you are iterating over clusters, that something like this would be more clear:

foreach my $cluster (@$clusters) { #..... }
So when do you need the extra {}? You need this when dereferencing an indexed expression, but not a non-indexed one. You also need the extra {} to make a list from a list ref returning function.
my @list = @{listRefReturningFunction()}; #also consider: my $r = {"a" => [1,2,3,4], "b" => [5,6,7,8], }; print @{$r->{"a"}}; #prints 1234 #here print @$r->{"a"} won't work #because this is a subscripted expression # now with list... my @x =(1,2,3,4); my $xref=\@x; print @$xref; #prints 1234 also #this works because there is no subscript

In reply to Re^2: perl, mysql: "fetchrow_array failed: fetch() without execute()" by Marshall
in thread perl, mysql: "fetchrow_array failed: fetch() without execute()" by gojira

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.