Fields won't add when reading a text file



In learning CGI/Perl I am trying to write a script that will read
records and print the total number of people registered for each
seminar.
This is the script I have been working on all day and the text file
which it reads follows it.


#!/usr/bin/perl
#list.cgi - reads form data to a file, and creates a dynamic
#Web page that displays people registering for different seminars.
print "Content-type: text/html\n\n";
use CGI qw(:standard -debug);
use strict;

#declare variables
my ($name, $seminar, @records, %sem_count);
my @name_count = (0);
my %sem_count = ("Computer Maintenance", 0,
"Microsoft Office", 0,
"Unix Essentials", 0,
"CGI/Perl", 0);

#calculate people registered and seminar count
open(INFILE, "<", "list.txt")
or die "Error opening list.txt. $!, stopped";
my @records = <INFILE>;
close(INFILE);
foreach my $rec (@records) {
chomp($rec);
($name, $seminar) = split(/,/ , $rec);
$name_count [$name] = $name_count[$name] + 1;
$sem_count {$seminar} = $sem_count{$seminar} +1;
}

#generate HTML
print "<html><head><title>Seminar Workshop</title></head>\n";
print "<body>\n";
print "<table>\n";
print "<tr align='left'><th>Seminar</th> <th>Registered</th></tr>\n";
foreach my $key ("Computer Maintenance", "Microsoft Office", "Unix
Essentials", "CGI/Perl") {
print "<tr><td>$key</td> <td>$sem_count{$key}</td></tr>\n";
}
print "</table>\n";
print "<br /><br />Total registered: $name_count[$name]\n";
print "</body></html>\n";



Text file:

Janice Alto,3
Nancy Perez,1
James Houza,2
Beth Jimminez,2
Michael Hiller,4
Inez Smith,4
Paul Eniudo,3
Tess Bacza,2
Robert Hau,1
Opal Jones,2



The first field in the text file is a name which I have been able to
add all together to get a total of 10. What I haven't figured out how
to do is total the second field to get the number attending each
seminar. The numbers represent which seminar by 1-Computer Maintenance,
2-Microsoft Office, 3-Unix Essentials, and 4-CGI/Perl. I keep coming up
with 0 for each event.

Thanks for any ideas you may have.

.



Relevant Pages

  • [HPADM] RE: Changes To Daylight Saving Time
    ... DST 2007 with HP and this script was never mentioned. ... HP ran an on-line seminar regarding best practices for the ... on HP-UX, Linux, and Tru64. ... It tests the OS readiness, ...
    (HP-UX-Admin)
  • Re: Publish America Victim. [stadia]
    ... She wants to excuse principal coups apart from Muhammad's ... seminar. ... Who supposes off, when Sara crushs the liable unit ... conversation under the script. ...
    (rec.models.rockets)
  • [HPADM] Changes To Daylight Saving Time
    ... HP ran an on-line seminar regarding best practices for the changes to Daylight Saving Time. ... It runs on HP-UX, Linux, and Tru64. ... and on HP-UX supplies applications that could have aC++ issues. ... This script brought to light a number of issues in our environment including the fact that our RedHat servers were not ready to go! ...
    (HP-UX-Admin)