Sponsored Content
Top Forums Shell Programming and Scripting Can't get my head wrapped around CGI/Perl Post 302280253 by sennex on Monday 26th of January 2009 10:57:42 AM
Old 01-26-2009
Below the code is a rough breakdown of the TXT file I am pulling in from.
I ran a basic perl -c on this to see any syntax errors, and I got back a
"Global symbol "@semm_count" requires explicit package name at Line 24.

So I apparently have that variable set wrong, but I am not sure how. I am missing some larger piece and not sure what it is or how to get it to click in my head, I am thinking about this way to much. SQL wasn't this hard to pick up and neither was Flash or Javascript

All I need to get this to do is display:

Seminar Name: Number registered:
1 2
2 3
3 1
4 2
total Students registered: 8

Code:
#!c:/perl/bin/perl.exe
#super.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);
use strict;

#declare variables
my ($name, $semm, @records);
#my @semm_count = (0, 0, 0, 0);
my %semm_count = ("1", 0,
				  "2", 0,
				  "3", 0,
				  "4", 0);

#calculate survey statistics
open(INFILE, ">>", "c05ex5.txt")
	or die "Error opening c05ex5.txt. $!, stopped";
@records = <INFILE>;
close(INFILE);
foreach my $rec (@records) {
	chomp($rec);
	($name, $semm) = split(/,/, $rec);
	$semm_count[$semm] = $semm_count[$semm] + 1;
	}

#generate HTML acknowledgment
print "<HTML><HEAD><TITLE>WKRK-TV</TITLE></HEAD>\n";
print "<BODY>\n";
print "<H2>Seminar Total</H2>\n";

print "<TABLE>\n";
print "<TR><TD>Seminar</TD>    <TD>Total</TD></TR>\n";

foreach my $key ("Computer Maintenance", "Microsoft Office", "Unix Essentials", "CGI/PErl") {
	print "<TR><TD>$key</TD> <TD>$semm_count{$key}</TD></TR>\n";
	}

print "</TABLE>\n";
print "</BODY></HTML>\n";


Text file:
StudentA,1
StudentB,2
StudentC,3
StudentD,4
StudentE,1
StudentF,2
StudentG,2
StudentH,4



 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl CGI.pm

my box is FreeBSD4.3 and I use Perl 5.0005_03. Here is the CGI script. test.cgi ...... if ($query->action eq 'detail') { ...... print $query->hidden('action', 'modify'); ...... } I found that the result of test.cgi?action=detail is not what I expected. the script does not... (4 Replies)
Discussion started by: tonyt
4 Replies

2. UNIX for Dummies Questions & Answers

Apache Perl/CGI

Can any body help me with apache and cgi i'dont know how iconfigure apache to use cgi... and when i try to start apachectl it says there is no file... please help me...i have apache installed... (1 Reply)
Discussion started by: CreamHarry
1 Replies

3. Shell Programming and Scripting

perl+CGI+mysql !!!!!!!

hi expert, I am totally new to perl CGI coding. And stop by below issue: 1> i have a script names conn.pl, which can connect to mysql and get the information of table user(id,name) 2> i copied above code into one CGI web page named user.cgi 3> when i view user.cgi in web browser, it toldme... (3 Replies)
Discussion started by: summer_cherry
3 Replies

4. Web Development

problem with exporting vairable from one perl cgi to another perl cgi script while redirecting.

Can anyone tell me how to export a variable from one perl CGI script to another perl cgi script when using a redirect. Upon running the login.pl the user is prompted to enter user name and password. Upon entering the correct credentials (admin/admin) the user is redirected to welcome page. My... (3 Replies)
Discussion started by: Arun_Linux
3 Replies

5. Shell Programming and Scripting

CGI in Perl

Hi, Am unfamiliar with using CGI modules in Perl. Though i checked in few sites about CGI , i dint get a clear idea. Can anyone please explain me the purpose of these statements, it ll be very helpful to me #!/usr/bin/perl use CGI qw/:standard/; use Storable; use Data::Dumper; my... (1 Reply)
Discussion started by: irudayaraj
1 Replies

6. Shell Programming and Scripting

Perl cgi pages out of cgi-bin folder in WINDOWS

Hi team, I have a typical problem with cgi pages in apache webserver in WINDOWS I am able to execute(display) the pages that are saved in cgi-bin folder. But I am not able to execute the pages stored in htdocs or other folder other than cgi-bin folder. Could anyone please let me know how... (1 Reply)
Discussion started by: scriptscript
1 Replies

7. Shell Programming and Scripting

Perl CGI : unable to download the excel sheet from perl cgi page

Hi All, I have written an cgi perl script that displays an image(Excel image) and when clicked on that Image I need to download a excel sheet. I made sure that excel sheet exists in the folder with the given name but still I am not able to download the sheet. print "<center><table... (2 Replies)
Discussion started by: scriptscript
2 Replies

8. Shell Programming and Scripting

CGI Perl : while loop in CGI perl

Hi Team, I am trying to connect to database(succeeded ) and print the records on the browser using while loop. But the elements of array are not displayed instead while loop is displayed directly. Instead of the below I can embed html statements in print but I am looking for the below style as I... (1 Reply)
Discussion started by: scriptscript
1 Replies

9. OS X (Apple)

Perl CGI

I am trying to get my MacBook Pro with 10.8 Mt Lion set up to run Perl CGI scripts. Having a problem. I can start Apache Web Server with no problems. Why do I put the static and dynamic scripts? I which directory? I have looked at this article:... (3 Replies)
Discussion started by: djehresmann
3 Replies

10. UNIX for Dummies Questions & Answers

PERL-CGI learning

Hello All, I am actually learning PERL and more interested to learn CGI script too. Can any suggest a forum or weblink which is more helpful for a dummy CGI developer. Thanks (6 Replies)
Discussion started by: posix
6 Replies
split(n)						       Tcl Built-In Commands							  split(n)

__________________________________________________________________________________________________________________________________________________

NAME
split - Split a string into a proper Tcl list SYNOPSIS
split string ?splitChars? _________________________________________________________________ DESCRIPTION
Returns a list created by splitting string at each character that is in the splitChars argument. Each element of the result list will con- sist of the characters from string that lie between instances of the characters in splitChars. Empty list elements will be generated if string contains adjacent characters in splitChars, or if the first or last character of string is in splitChars. If splitChars is an empty string then each character of string becomes a separate element of the result list. SplitChars defaults to the standard white-space char- acters. EXAMPLES
Divide up a USENET group name into its hierarchical components: split "comp.lang.tcl.announce" . -> comp lang tcl announce See how the split command splits on every character in splitChars, which can result in information loss if you are not careful: split "alpha beta gamma" "temp" -> al {ha b} {} {a ga} {} a Extract the list words from a string that is not a well-formed list: split "Example with {unbalanced brace character" -> Example with {unbalanced brace character Split a string into its constituent characters split "Hello world" {} -> H e l l o { } w o r l d PARSING RECORD-ORIENTED FILES Parse a Unix /etc/passwd file, which consists of one entry per line, with each line consisting of a colon-separated list of fields: ## Read the file set fid [open /etc/passwd] set content [read $fid] close $fid ## Split into records on newlines set records [split $content " "] ## Iterate over the records foreach rec $records { ## Split into fields on colons set fields [split $rec ":"] ## Assign fields to variables and print some out... lassign $fields userName password uid grp longName homeDir shell puts "$longName uses [file tail $shell] for a login shell" } SEE ALSO
join(n), list(n), string(n) KEYWORDS
list, split, string Tcl split(n)
All times are GMT -4. The time now is 11:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy