Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

i had something running on my machine to output code it worked half an hour ago then i copied and pasted it into another sript recreated the database and now it doesn't work the code is as follows i keep getting an unitialised value at the line
print "<td>$list_of_teamdata[0][1]</td> \n";
the full program is
my @list_of_teamdata ; $pain = 0; while (@row = $sth5->fetchrow_array()) { $round= $row[0]; $teamname= $row[1]; $score= $row[2]; $list_of_teamdata[$pain][0] = $round; $list_of_teamdata[$pain][1] = $teamname; $list_of_teamdata[$pain][2] = $score; $pain++; } print "<table border=1> \n"; print "<tr> \n"; print "<th> List of info </th> \n"; print "<tr> \n"; print "<tr> \n"; print "<td>$list_of_teamdata[0][1]</td> \n"; print "</tr> \n"; print "</table>"; print "</body>"; print "</html>";
i'm running out of hair to rip out why would that value be un anitialised. i altered the atabase by delete and then i recreated it with the same script as before.

Replies are listed 'Best First'.
Re: yet more dbi issues
by davorg (Chancellor) on Apr 03, 2001 at 18:54 UTC

    The part of your code where you fill in the array of arrays could be written far more efficiently like this:

    my @list_of_teamdata; while (my @row = $sth5->fetchrow_array()) { push @list_of_teamdata, \@row; }

    As for your "uninitialised value" error, I'd look at the database and make sure you don't have any null values in the teamname column.

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

      Or just use fetchall_arrayref (or selectall_arrayref):
      my @list_of_teamdata = @{$sth->fetchall_arrayref}; # or just rewrite the rest to use an array ref my $list_of_teamdata = $sth->fetchall_arrayref;
Re: yet more dbi issues
by lachoy (Parson) on Apr 03, 2001 at 18:49 UTC

    How do you know it's initialized? Why don't you put a statement in so you can tell what's actually being retrieved from the database:

    # Also, you should use 'my' to ensure you get a new # array every time while ( my @row = $sth5->fetchrow_array() ) { $round= $row[0]; $teamname= $row[1]; $score= $row[2]; # If you're running in a webserver, this should # appear in the error log. You can also try # to print this out to the browser. warn "Retrieved row: ($round) ($teamname) ($score)\n"; $list_of_teamdata[$pain][0] = $round; $list_of_teamdata[$pain][1] = $teamname; $list_of_teamdata[$pain][2] = $score; ... }

    Chris
    M-x auto-bs-mode