First, use strict and enable warnings (yes, again with that ... it will help you catch errors such as "unintialized value" errors (which, from your description, is highly likely to be the problem here), and keep you from having to come back to us as often as you are).

It is not enough to sprinkle your code with my declarations, you need to enable the checks!

Second, let me comment on your DB code:

$sth = $dbh->prepare("SELECT year from trees WHERE sport = \'$sport\' +AND year = + \'$year\'") || die "couldn't prepareSQL statement"; $sth->execute || die "can't execute sql statement"; my @row; while (@row = $sth->fetchrow_array()) { $year = $row[0]; }

Learn to use placeholders: that prepare is more securely written as

$sth = $dbh->prepare('SELECT year FROM trees WHERE sport = ? AND year = ?' );

When you do that, you put the variables that are going into the places that are being held into the execute call:

$sth->execute($sport, $year) or die "Can't execute: ". $db->errstr(). "\n";

Finally, since you know you're only snagging one datum, that while loop (which appears in more than one spot here) has the potential to confuse. Just do

my ($year) = $sth->fetchrow();

and follow that up with a $sth->finish.

OK, now for your hashes: you could do both hashes in one go:

for (1.. $compsize *2 -1) { $teams{"team$_"} = $cgi->param("team$_"); $scores{"score$_"} = $cgi->param("score$_"); }

Now, if the hashes aren't populated the way you think they should be, the most likely thing that's going on is that you're not getting parameters of the right form: so check that out first, put in some debugging code such as:

print "<ul>\n"; foreach ( $cgi->param) { print "<li>$_: '", $cgi->param($_) ,"'\n"; } print "</ul>\n";

This will tell you whether you're getting the input you think you're getting.

Philosophy can be made out of anything. Or less -- Jerry A. Fodor


In reply to Re: script problems1 by arturo
in thread script problems1 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.