#1 (permalink)  
Old 04-29-2006, 03:39 PM
NevadaSam's Avatar
Registered User
 
Join Date: Apr 2006
Posts: 20
Fields won't add.

Fields won't add.

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.

Quote:
#!/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:
Quote:
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.
Reply With Quote

  #2 (permalink)  
Old 04-30-2006, 11:57 AM
Till's Avatar
Administrator
 
Join Date: Jan 2002
Location: Berlin, Germany
Posts: 1,453
Code:
($name, $seminar) = split(/,/ , $rec);
$name_count [$name] = $name_count[$name] + 1;
$sem_count {$seminar} = $sem_count{$seminar} +1;
When do you use [ ] and when { } ?
Reply With Quote
  #3 (permalink)  
Old 04-30-2006, 03:25 PM
NevadaSam's Avatar
Registered User
 
Join Date: Apr 2006
Posts: 20
Quote:
Originally Posted by Till
Code:
($name, $seminar) = split(/,/ , $rec);
$name_count [$name] = $name_count[$name] + 1;
$sem_count {$seminar} = $sem_count{$seminar} +1;
When do you use [ ] and when { } ?
Thanks. Brackets [] are used when it is an array and braces {} are used if it is a hash.

I have found how to code the script for this task. So problem solved.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
passing information from 1 form to another amanxman Programming and Scripting 3 04-12-2006 04:59 PM
mail.php assistance anyone? awarner20 Programming and Scripting 1 02-25-2006 07:42 PM
Really Hidden Form Fields curtiss Programming and Scripting 3 08-15-2005 05:26 PM
"Lookup" in HTML Forms RickKnight Programming and Scripting 11 05-13-2005 12:49 PM
Why oh why do my ASP fields turn yellow when Live?? vibejunkie Programming and Scripting 1 05-04-2005 04:56 PM


All times are GMT -5. The time now is 05:28 PM.

 
Bitrix
Clicky Web Analytics
CloudContacts
Maxtango


Subscribe to our feed | add to myYahoo!

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
© 1997-2007 HTMLCenter