1 / 12

Data files using cgi/perl

Data files using cgi/perl. Please use speaker notes for additional information!. <!mailinglist.html> <html> <head><title>Mailing List</title></head> <body> <h1>Mailing List</h1> <form action="http://www.pgrocer.com/cgi-bin/data/maillist.cgi" method=post> Enter Name:<br>

kirkan
Télécharger la présentation

Data files using cgi/perl

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data files using cgi/perl Please use speaker notes for additional information!

  2. <!mailinglist.html> <html> <head><title>Mailing List</title></head> <body> <h1>Mailing List</h1> <form action="http://www.pgrocer.com/cgi-bin/data/maillist.cgi" method=post> Enter Name:<br> <input type=text name=name size=25><br><br> Enter Address:<br> <input type=text name=stadr size=25><br><br> Enter City:<br> <input type=text name=city size=20><br><br> Enter State:<br> <input type=text name=state size=2<br><br> Enter ZIP: <input type=text name=zip size=10<br> <input type=submit value="Submit"> <input type=reset value="Reset"> </form> </body> </html>

  3. #!/usr/bin/perl #maillist.cgi - saves name and address information to make a mailing list use CGI::Carp qw(fatalsToBrowser); print "Content-type: text/html\n\n"; use CGI qw(:standard); use strict; #declare variables my ($name, $stadr, $city, $state, $zip); #assign variables $name = param('name'); $stadr = param('stadr'); $city = param('city'); $state = param('state'); $zip = param('zip'); #save form data to a file open(FILEOUT, ">>", "maillist.txt") or die "file error: maillist.txt. $!, stopped"; print FILEOUT "$name, $stadr, $city, $state, $zip\n"; close(FILEOUT); print "<html><head><title>Record just entered</title><basefont size=5></head>\n"; print "<body>\n"; print "<div align=center>\n"; print "$name, $stadr, $city, $state, $zip\n"; print "</div></body></html>\n";

  4. #!/usr/bin/perl #maillist.cgi - saves name and address information to make a mailing list use CGI::Carp qw(fatalsToBrowser); print "Content-type: text/html\n\n"; use CGI qw(:standard); use strict; #declare variables my ($name, $stadr, $city, $state, $zip); #assign variables $name = param('name'); $stadr = param('stadr'); $city = param('city'); $state = param('state'); $zip = param('zip'); #save form data to a file open(FILEOUT, ">>", "maillist.txt") or die "file error: maillist.txt. $!, stopped"; print FILEOUT "$name, $stadr, $city, $state, $zip\n"; close(FILEOUT); print "<html><head><title>Record just entered</title><basefont size=5></head>\n"; print "<body>\n"; print "<div align=center>\n"; print "$name, $stadr, $city, $state, $zip\n"; print "</div></body></html>\n"; FILEOUT is opened to append (this is indicated by the >>. The name of the file is maillist.txt. The error line will catch problems opening the file. The record that is written to the file contains all of the fields that were inputted on the html form and then stored in variables in this code.

  5. #!/usr/bin/perl #maillistrd.cgi - reads the mail list file use CGI::Carp qw(fatalsToBrowser); print "Content-type: text/html\n\n"; use CGI qw(:standard); use strict; #declare variables my ($name, $stadr, $city, $state, $zip, @records); open(INF, "<", "maillist.txt") or die "file error: maillist.txt. $!, stopped"; @records=<INF>; close(INF); print "<html><head><title>Records on mail list</title><basefont size=5></head>\n"; print "<body>\n"; print "<h1>Mailing list:</h1>\n"; foreach my $record (@records) { chomp($record); ($name, $stadr, $city, $state, $zip) = split(/,/, $record); print "$name, $stadr, $city, $state, $zip<br>\n"; } print "</body></html>\n"; This code reads the records on the maillist.txt file into @records. I then process @records by going through each record individually using the foreach which establishes $record as an individual record from @records.

  6. <!degreeopts.html> <html> <head><title>Degree CIS</title></head> <body> <h1>Degree Options in CIS</h1> <form action="http://www.pgrocer.com/cgi-bin/data/degreeopts.cgi" method=post> <b>Which option are you enrolled in?</b><br> <input type=radio name=option value=0>Webmaster<br> <input type=radio name=option value=1>Programming<br> <input type=radio name=option value=2>Networking<br> <input type=radio name=option value=3>Multimedia and the Internet<br> <input type=radio name=option value=4>Business Information Systems<br> <input type=radio name=option value=5>Information Systems Transfer<br> <input type=radio name=option value=6>Computer Science Transfer<br> <input type=submit value="Submit"> </form> </body> </html>

  7. #!/usr/bin/perl #degreeopts.cgi - saves form data to a file and reports results use CGI::Carp qw(fatalsToBrowser); print "Content-type: text/html\n\n"; use CGI qw(:standard); use strict; #declare variables my ($option, @records); my @options_total = (0, 0, 0, 0, 0, 0, 0); #assign variables $option = param('option'); #save form data to a file open(FILEOUT, ">>", "totals.txt") or die "file error: totals.txt. $!, stopped"; print FILEOUT "$option\n"; close(FILEOUT); Notice that each record on the file contains only the $option.

  8. #read file and accumulate totals in an array open(FILEIN, "<", "totals.txt") or die "file error: totals.txt. $!, stopped"; @records=<FILEIN>; close(FILEIN); #display contents of array on screen foreach my $record(@records) { chomp($record); $options_total[$record]= $options_total[$record]+1; } print "<html><head><title>CIS Degree Options</title><basefont=5></head>\n"; print "<body>\n"; print "<div align=center>\n"; print "<h2>Information about degree options in the CIS department.</h2>\n"; print "<table width = 50% border=2>\n"; print "<tr><td colspan=2>Number of students in CIS Degree options:</td></tr>\n"; print "<tr><td>Webmaster</td><td>$options_total[0]</td></tr>\n"; print "<tr><td>Programming</td><td>$options_total[1]</td></tr>\n"; print "<tr><td>Networking</td><td>$options_total[2]</td></tr>\n"; print "<tr><td>Multimedia and the Internet</td><td>$options_total[3]</td></tr>\n"; print "<tr><td>Business Information Systems</td><td>$options_total[4]</td></tr>\n"; print "<tr><td>Information Systems Transfer</td><td>$options_total[5]</td></tr>\n"; print "<tr><td>Computer Science Transfer</td><td>$options_total[6]</td></tr>\n"; print "</table>\n"; print "</div></body></html>\n";

More Related