home -- outline -- lectures -- assignments -- discussion -- tips -- links --



Virtual Museum: Assignment Layout

Using Variables:
  • $VM_file = "/usr/local/classes/CS101/html/assignments/VM/"
  • $VM_image = "/classes/CS101/html/assignments/VM/"

    open(FILE, "$VM_file/painters/bio1.txt");

    print "<img src="$VM_image/paintings/thumb4.jpg">


  • $choice=¶m'painting';

    print "< img src="$VM_image/paintings/thumb$choice.jpg">
Using Split:

Typically, we've used split for files that are many lines long. For a file that is just a single line of text, you do not have to use a while loop: simply say:

$_=<FILE>

This will read the first (and only) line of your short text files into the variable $_. Think about control structures and why you use them.

  • The painter.txt format - last name : first name(s) :date of birth:date of death:nationality\n
  • The title.txt format - last name:first name:title of painting:style of painting:date of painting\n
  • The bio.txt format - text
FILES
  • You don't have to use the open command for images... just print the image link using a variable and leave it at that!
What's required The main page for your museum should allow the user to:
  • Search for a title
  • Search for a painter
  • Search for a keyword in all text fields (biographies and titles)
First, build a page with a form for the three search fields. How does the person enter the search? Is it a plain text entry field or a pulldown menu? Tradeoffs? However you decide, the form needs to pass the correct information (ie: a NUMERICAL VALUE or STRING) to the correct cgi program -

  • painter.cgi
    This script takes as input the number of a painter and dynamically generates a web-page for this painter containing :

    • a title bar with the painter's name and his dates (if available) - from painter.txt
    • a biography - from bio.txt
    • a list of names of the painter's paintings with thumbnails - from title.txt files


    FIRST, write the code that finds the appropriate painter.txt

    • assign a number to each painter?
    • for loop that searches for the correct painter?
    • other ways to do it??


    NEXT, write a the code that finds the correct bio

    • for loop that searches for the correct bio?
    • posted foreach code - how does it work?
    • other ways to do it??


    THEN, write the code that finds the thumbnail files. What do you have to do?

    • Use a for loop or a while loop with a counter to look through all the title.txt files for the painter's name.
    • NOTE: If you're gonna write this code to find the painter's name in the title files, why not use this same code for your bio search and painter.txt search??

    Once you've found the artist's name in the text file, use that counter match up the title with the corresponding thumbnail:

    • title1.txt has the artist for thumb1.jpg
    • title2.txt has the artist for thumb2.jpg
    • So using a count to replace the number of the file you get

      title$count.txthas the artist for thumb$count.jpg


    See, now you have a page that can print the Artist's name and bio AND thumbnails of related paintings. Not to shabby! And from this page you can link to painting.cgi

  • The painting.cgi takes a painting number and displays a dynamically generated page with:

    • a larger version of the picture
    • the title
    • the artist
    • the style
    • the date.


    Some issues to consider:

    • How to sending a number to this script?
      Using the image as a link:
      <a href="painting.cgi?painting=4"> Narcissus </a>
    • Layout: using the width (or height) attribute of < IMG> to resize them


  • NOW you can focus on the Title search for your main museum page. Here we basically need the same loop that you used to match titles with thumbnails from the painter.cgi. So build yourself a title_search.cgithat takes this code, and then passes the count variable on to painting.cgi.

  • FINALLY, after you have build this whole thing, you can implement the Keyword Search on your main museum page.

    Use a text input field to submit any number of keywords to a cgi. This cgi should generate a list of painter and painting links that match any of these keywords (so Caravaggio should get me a link to the painter page for Caravaggio and a link for each of his paintings).

    Remember: a list of keywords will match anything that matches any of the keywords. In the above example every link relating to either Italy or France should be returned for the search France Italy.

    How do we do this in Perl? (suppose the keywords we are searching for are in the variable $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
      };
    
    
    This code takes the variable $keywords and splits it up by white spaces into several keywords and then joins them back together putting a bar (|) where the spaces were.

    So $search will contain a pattern that tries to match any of the keywords (the i after the pattern makes the pattern case insensitive).

    The following piece of code will search all the biography files for the pattern $keyword.

     
    $VM = "/usr/local/classes/CS101/html/assignments/VM";
    foreach $counter (1,2,3,4,5,6) {
          open (FILE, "$VM/painters/bio$counter.txt");
                $_ = ;
                while (!eof && !($_ =~ /$keyword/)) {
                   $_ = ; 
                }
                if ($_ =~ $keyword) { 
                   print "FOUND KEYWORD 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.

That's it! You've finished the keyword search, and can now search for artist and title as well! Remember: because each of these features uses a different script, they should each have their own submit button!

Schedule

This assignment (#8) is due Friday 3/6. For Assignment #9, however, we are letting you re-do a past assignment (and I SWEAR the grades will be up by Friday, so you can decide whether or not you want to re-do a grade). So if you want an extension on this assignment, you can just skip #9 and turn this in on Wednesday 3/11, which is when #9 is due. In addition, you can do the Extra Credit listed below, which is due Friday 3/13. We will give you the Final on Monday, 3/9 and it will be due Wednesday 3/18, no exceptions. So the schedule looks like:


3/6:    #8 due
(3/9:     Final Out)
3/11:   #9 (make-up) or Extension for #8 due
3/13;   Extra Credit for #8 due
3/18:   Final Due


Extra credit
There are several things you can do to get extra credit in order of increasing difficulty:

  • 2 points Fix the Rembrandt problem: suppose somebody entered Rembrandt. Should that be searched for in the first name field or the last name field? For that matter what about Caravaggio and Michelangelo? Adapt the search in such a way that Caravaggio would be found if it was entered in the first name or the last name field.)

  • 2 points On your homepage have a surprise link that takes you to a random painting. (For this you will need the 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.)

  • 4 points Include a link that takes you through a walk of the museum, all paintings in order. On each new page with a painting there should be a link to the next painting, and a link back to the main page. (Hint: you'll need a cgi that gets the number of the current painting as input, to generate the next page).

  • 4 points Randomize the walk through the museum.

  • 8 points (Very difficult) Implement a random walk through the museum that does not take you by the same painting twice.