home -- outline -- lectures -- assignments -- discussion -- tips -- links -- | |
![]() ![]() | |
![]() |
open(FILE, "/usr/local/classes/CS101/html/assignments/VM/painters/bio1.txt");
$VM = "/usr/local/classes/CS101/html/assignments/VM/"
open(FILE, "$VM/painters/bio1.txt");
painter1.txt
to painter6.txt
and
bio1.txt
up to bio6.txt
. Files with the same
number belong together. The painter files contains information
about the painter, for example painter1.txt looks like this:
Bocklin:Arnold:1827:1901:Swiss
Caravaggio:Michelangelo Merisi:Narcissus:oil on canvas:
painting.cgi
which takes as input a number
(suppose the field with the number is called painting) of
a painting (in our case a number from 1 to 10, since we only have
ten paintings) and displays a dynamically generated page for the painting having
this number. The page should contain the title of the painting, the date it was
painted, the style, and finally the painting itself (if you think the
paintings are too large for your layout, use the width (or height) attribute
of <IMG>
to resize them).
Since the ¶m
function works with both POST and GET
you can use your cgi to run with forms using both methods, and have direct links
to it, e.g. <a href="painting.cgi?painting=4">Narcissus</a>
.
painter.cgi
which takes as input the number of
a painter (in our case a number from 1 to 6, since we only have six painters)
and dynamically generates a web-page for this painter, containing
eq
is good enough.
painting.cgi
with the number of the painting as a value for painting. For example
if you just found out that Caravaggio painted Narcissus your cgi should generate a link
like the following: <a href="painting.cgi?painting=4">Narcissus</a>
.
search_title.cgi
. This cgi will look at all the title files
and return a list of links (to painting.cgi
!) with thumbnails and names of paintings that match
the keywords you specified in the form.
eq
). Or you might consider the search title
as a pattern and try to match it against the titles you find in the files. In the last
case you should do some preprocessing on your search string, for example
substitute multiplie spaces (which a user might have entered
by accident) by a single space (hint: try
$search_string =~ /\s+/ /g
).
painting.cgi
!). The strategies described above for title
search also apply to painter search, but here you should have two fields: first name
and last name. The user should be able to specify both, one, or none (in the last case
he should get a listing of all painters).
France Italy
$keywords
and the text
we are searching is in $text
).
$search = join("|",split(/\s+/,$keywords));
if ($text =~ /$search/i) {
whatever you want to do in case the
search is successful
};
i
after the pattern makes the pattern case insensitive.
$VM = "/usr/local/classes/CS101/html/assignments/VM";
foreach $counter (1,2,3,4,5,6) {
open (FILE, "$VM/painters/bio$counter.txt");
$_ = <FILE>;
while (!eof && !($_ =~ /$keyword/)) {
$_ = <FILE>; };
if ($_ =~ $keyword) { print "FOUND KEYOWORD IN BIO$counter.txt"; };
close FILE;
};
Note that we are testing for whether we have found the end of the file (eof). If
so we have to stop searching (otherwise we would run into an infinite loop.
rand
function to generate a random
number. For example $surprise = int(rand(10)+1
will assign
a random integer number between 1 and 10 to the variable $surprise
.
Then you can either use redirection (Location header) or a rewritten form of the
painting.cgi script.)