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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |