I don't know whether you cut-and-pasted or typed it in directly, but some changes are below:

# 'strict' is your friend! use strict; ... # be sure to end each statement with a semicolon, and declar # all variables with 'my' my $sport = 'basket ball'; my $year = '1999'; # Egads, escaping quotes is so un-Perlish. DBI # placeholders make life much easier my $sql = qq/ SELECT round, teamname, score FROM trees WHERE sport = ? and year = ? ORDER BY round DESC /; # Turn on DBI error checking -- anything with an error # will immediately trigger 'die' $dbh->{RaiseError} = 1; # Prepare and plug in the values for the placeholders my $sth5 = $dbh->prepare( $sql ); $sth5->execute( $sport, $year ); my $rowcount = 0; my @list_of_teamdata = (); # It's probably easier to do this with hashes, but we'll # stick with your use of arrays. Fetching arrayrefs can # be faster, however, so we'll use those while ( my $row = $sth5->fetchrow_arrayref() ) { my $round = $row->[0]; my $teamname = $row->[1]; my $score = $row->[2]; # Using 'qw' as you had done isn't what you wanted -- # instead, just create an anonymous arrayref and stick # it in the list of results push @list_of_teamdata, [ $round, $teamname, $score ]; $rowcount++; } # Now print out your results -- use 'printf' for nicer # formatting :-) foreach my $info ( @list_of_teamdata ) { print "round $info->[0] team $info->[1] score $info->[2]\n"; }

There are more concise ways of doing this, but I wanted to change things just enough to work. We can get to efficiency and readability later :-)

Chris
M-x auto-bs-mode


In reply to Re: dbi issues by lachoy
in thread dbi issues by Anonymous Monk

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.