Chris Pollett >
Old Classes >
PIC40

   ( Print View )

Lecture Notes-PDF

Spring '01 Ad: Enrollment info

Course Info: Homework Assignments:
Practice Exams:
PIC:
                           












HW#3 --- last modified January 16 2019 00:35:22..

Solution set.

Due date: noon Feb. 9
=========

Files to be submitted:  p40hw3file1.cgi --put in your \SUBMIT folder
======================                    and on your UNIX account
                                          make a directory
                                          ~/public_html/hw3 and
                                          put it in there as well.
                                          Do a chmod 755 on directory
                                          and file.

HW3 Purpose: To learn about Perl functions and to learn about how to handle
============ files in Perl. Also to write our first CGI program.

Specification:
==============
For this assignment you are going to write a short perl script which
keeps a count of how frequently people from any given site are
accessing it. The information of who requested p40hw3file3.cgi is
stored in the value corresponding to the key REMOTE_HOST
in the Perl %ENV hash. You should store in a file named data
a table of host names followed by a space followed by the number
of times that site has accessed your file. When your page file is
accessed, your script reads this table into a hash then looks
up the appropriate REMOTE_HOST given in %ENV, increments this
number in your hash and writes back out the result. To do this update your
Perl script
should call a function GetUpdate (which you write) which reads in the
table  stored in file $_[0], performs the update on this table, and writes
back out to the file $_[0]. GetUpdate should use a my local variable
to store the table. When done GetUpdate returns the value of this variable
viewed as a list to where it was called from.  Remember if a
REMOTE_HOST that has never accessed your site before accesses it you must
add a new line to your file. Once
you've performed this update your script should print out the HTML
necessary to generate the following kind of output:

Welcome. You are the 00123 visitor from math.ucla.edu.

Below is a frequency table of other sites requesting this page:

julia.ucla.edu 00003
gentzen.logic.net 00015
vax.pbs.org 00001
You can look at this pages source to see how this table was written.
Your Perl script should use two auxiliary function in generating this
output. The first one, MakeHead outputs the head of the document.
$_[0] should be used as the title. The second one DrawTable
outputs the table. You should pass the current remote host and the table
to this function so that the @_ it receives looks like:
   ($current_remote_host, %table_of_other_hosts )

Point Breakdown for HW3
=======================
Code is well documented
   and whole program works.............1pt
GetUpdate takes correct
 arguments and returns correct value...1pt
GetUpdate reads in data correctly......1pt
GetUpdate updates data correctly
 including adding new entries..........1pt
GetUpdate write out data correctly.....1pt
MakeHead works as described............1pt
DrawTable takes correct arguments......1pt
DrawTable generates table as above.....1pt

Total..................................8pts
Bonus:
======
File to submit: p40hw3bon1.plx -- just in your \SUBMIT folder

Due Date of Bonus: Same as HW4 due date.

Purpose: To experiment with Perl/Tk GUI's. To learn a little about writing
======== web clients.

Value: +3 points to your score after curving for a completely working
====== project.
       Only +1 if the TCP connection function to time-b.nist.gov gets time
         correctly
       Only +2 if clock face drawing function works correctly and update
         every second correctly.

Specification
=============
Your goal in this assignment is write a Perl script which pops up a window
with a canvas on it. On this canvas should be drawn an analog clock
with a second, minute, and hour hand. This clock should tell the
time according to the Pacific Time Zone. To make sure the time your
is accurate, every five minutes your clock should open a TCP connection
to time-b.nist.gov (which has the official time for the US.). When
this connection is accepted, this site immediately sends back the current
time in ASCII and closes the connection. So you should read what is sent
back and close your TCP file handle. You should experiment with this to
see the format of the time string or look National Institute of
Standards Time Site.

People who are interested in working on this Bonus should meet
with me Wednesday, Feb. 7, so I can go over what you need to know about
the Socket library for Perl and also talk about Perl/Tk.