I keep getting an error message:

Use of uninitialized value in addition <+> at c05ex1.cgi line 33. Argument "" isn't numeric in array element at c05ex1.cgi line 34.

I have done this just a my text book said to do. What am I missing?

#!/usr/bin/perl #c05ex1.cgi - saves form data to a file, and creates a dynamic #Web page that displays a message and survey statistics print "Content-type: text/html\n\n"; use CGI qw(:standard -debug); use strict; #declare variables my ($game, $commercial, @records); my %game_count = ("Great", 0, "Boring", 0, "None", 0); my @comm_count = (0, 0, 0, 0); #assign input items to variables $game = param('Game'); $commercial = param('Commercial'); #save form data to a file open(OUTFILE, ">>", "c05ex1.txt") or die "Error opening c05ex1.txt. $!, stopped"; print OUTFILE "$game,$commercial\n"; close(OUTFILE); #calculate survey statistics open(INFILE, "<", "c05ex1.txt") or die "Error opening c05ex1.txt. $!, stopped"; @records = <INFILE>; close(INFILE); foreach my $rec (@records) { chomp($rec); ($game, $commercial) = split(/,/, $rec); $game_count{$game} = $game_count{$game} + 1; $comm_count[$commercial] = $comm_count[$commercial] + 1; } #generate HTML acknowledgment print "<HTML><HEAD><TITLE>WKRK-TV</TITLE></HEAD>\n"; print "<BODY>\n"; print "<H2>Thank you for participating in our survey.</H2>\n"; print "<EM><B>What did you think of the Super Bowl game?</EM></B>\n"; print "<TABLE>\n"; print "<TR><TD>It was a great game.</TD> <TD>$game_count{Great}</TD +></TR>\n"; print "<TR><TD>It was a boring game.</TD> <TD>$game_count{Boring}</T +D></TR>\n"; print "<TR><TD>I didn't watch the game.</TD><TD>$game_count{None}</TD> +</TR>\n"; print "</TABLE><BR>\n"; print "<EM><B>Vote for your favorite Super Bowl commercial:</EM></B>\n +"; print "<TABLE>\n"; print "<TR><TD>Budweiser</TD> <TD>$comm_count[0]</TD></TR>\n"; print "<TR><TD>FedEX</TD> <TD>$comm_count[1]</TD></TR>\n"; print "<TR><TD>MasterCard</TD> <TD>$comm_count[2]</TD></TR>\n"; print "<TR><TD>Pepsi</TD> <TD>$comm_count[3]</TD></TR>\n"; print "</TABLE<BR>\n"; print "</BODY></HTML>\n";

When the array was Game and the hash was Commercial it worked. Instructions said to make Commercial the array and the Game the Hash.

Help me please.
student.

20050516 Janitored by Corion: Added formatting


In reply to help with counters in perl by student in perl/cgi

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.