>", "maillist.txt") or die "file error: maillist.txt. $!, stopped"; print FILEOUT "$name, $stadr, $city, $state, $zip\n"; close(FILEOUT); print " Record just entered \n"; print " \n"; print "$name, $stadr, $city, $state, $zip\n"; print " \n";"> >", "maillist.txt") or die "file error: maillist.txt. $!, stopped"; print FILEOUT "$name, $stadr, $city, $state, $zip\n"; close(FILEOUT); print " Record just entered \n"; print " \n"; print "$name, $stadr, $city, $state, $zip\n"; print " \n";">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Data files using cgi/perl Please use speaker notes for additional information!"— Presentation transcript:

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

2 Mailing List Mailing List Enter Name: Enter Address: Enter City: Enter State: Enter ZIP:

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 " Record just entered \n"; print " \n"; print "$name, $stadr, $city, $state, $zip\n"; print " \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 " Record just entered \n"; print " \n"; print "$name, $stadr, $city, $state, $zip\n"; print " \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= ; close(INF); print " Records on mail list \n"; print " \n"; print " Mailing list: \n"; foreach my $record (@records) { chomp($record); ($name, $stadr, $city, $state, $zip) = split(/,/, $record); print "$name, $stadr, $city, $state, $zip \n"; } print " \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

7

8 Degree CIS Degree Options in CIS Which option are you enrolled in? Webmaster Programming Networking Multimedia and the Internet Business Information Systems Information Systems Transfer Computer Science Transfer

9 #!/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.

10 #read file and accumulate totals in an array open(FILEIN, "<", "totals.txt") or die "file error: totals.txt. $!, stopped"; @records= ; close(FILEIN); #display contents of array on screen foreach my $record(@records) { chomp($record); $options_total[$record]= $options_total[$record]+1; } print " CIS Degree Options \n"; print " \n"; print " Information about degree options in the CIS department. \n"; print " \n"; print " Number of students in CIS Degree options: \n"; print " Webmaster $options_total[0] \n"; print " Programming $options_total[1] \n"; print " Networking $options_total[2] \n"; print " Multimedia and the Internet $options_total[3] \n"; print " Business Information Systems $options_total[4] \n"; print " Information Systems Transfer $options_total[5] \n"; print " Computer Science Transfer $options_total[6] \n"; print " \n";

11

12


Download ppt "Data files using cgi/perl Please use speaker notes for additional information!"

Similar presentations


Ads by Google