Wrox Programmer Forums
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Linux Programming, 2nd Edition section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 16th, 2005, 03:46 PM
Registered User
 
Join Date: Apr 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to perlstudent
Default counter not working?

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}</TD></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:D.
perl student.
 
Old March 17th, 2006, 08:48 AM
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

$game = param('Game');
$commercial = param('Commercial');

Should read:
my $game = param('Game');
my $commercial = param('Commercial');

If you are using strict.

HTH
Charlie

--
Don't Stand on your head - you'll get footprints in your hair
                                           http://charlieharvey.org.uk
                                              http://charlieharvey.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
A Hit Counter, PLEASE HELP !!!!! ARD_40 BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 April 23rd, 2006 06:25 AM
Looping with a counter? salhabb XSLT 0 October 4th, 2005 05:09 AM
Counter tp194 Javascript 1 September 2nd, 2004 08:02 AM
counter Adam H-W Classic ASP Basics 15 August 15th, 2003 11:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.