From jacobson@math-cs.cns.uni.edu Sun Jul 21 20:20:19 2002 Date: Sun, 21 Jul 2002 20:19:30 -0500 (CDT) From: Mark Jacobson To: 810-088-06@uni.edu Subject: PERL assignment for movies titles... Question from 088 PERL student, > I have been looking at the PERL assignment for Tuesday and I really have > no idea where to start on it. I've talked to a couple of people from > class and they have basically said the same thing. ----------------------------------------------------------------------- This is the first I have heard of any questions about this, so thanks for having the initiative to let me know by email about the need for help and direction. Questions are always welcome, especially during or at the beginning of class or by email in between classes. ----------------------------------------------------------------------- You are writing a PERL .cgi program, so you will need to study over the example programs, such as the ones that have this at the beginning: #!/usr/bin/perl -w use CGI qw(:standard); ----------------------------------------------------------------------- Here is what else you need to know: 1. The desired output would be:
  1. "Good Morning Vietnam"
  2. Adventures of Baron Munchausen
  3. Armageddon
  4. Big ...
  5. Wizard of Oz
  6. Young Frankenstein
and when viewing it on the web page you should see that the numbers of the ordered list go from 1 to 34, if you wanted to see the names or titles of ALL the movies. If you wanted to see only the Comedy category, the numbers would go from 1 to 14 since there are only FOURTEEN Comedy movies. 1 "Good Morning, Vietnam" 2 Adventures of Baron Munchhausen 14 Young Frankenstein ----------------------------------------------------------------------------- There were 51 quotes from comedy movies. 1 "Good Morning, Vietnam" 2 Adventures of Baron Munchausen 3 Big 4 Ghostbusters 5 Ghostbusters II 6 MASH 7 Much Ado About Nothing 8 Pretty Woman 9 Risky Business 10 Roxanne 11 The Graduate 12 The Princess Bride 13 Tommy Boy 14 Young Frankenstein There were 16 quotes from action/adventure movies. 1 Armageddon 2 Citizen Kane 3 Dances With Wolves 4 Enter the Dragon 5 Goldfinger 6 Jaws 7 Rocky 8 Terminator 9 Wizard of Oz There were 33 quotes from drama movies. 1 Casablanca 2 Gettysburg 3 Hoosiers 4 I Know What You Did Last Summer 5 Lucas 6 Rain Man 7 The Matrix 8 The Negotiator 9 Them! 10 Titanic 11 Wings of Desire 14 + 9 + 11 = 34 movies all together. You are totally familiar with this fact of 34 movies from the class27.html web page. 2. To remove the duplicates of the names, as there are a total of 101 quotes in the moviesPERL.txt database exported file, you use the techniques shown in the http://www.cns.uni.edu/~jacobson/088/class27.html web page and its reference to the http://student.cns.uni.edu/~venkman/moviesUnique2.txt and http://student.cns.uni.edu/~venkman/moviesUnique.txt and http://student.cns.uni.edu/~venkman/moviesUnique3.txt web pages. 3. Here is the code for how I displayed just the comedy category of movies. ------ Note that the category values in the database are: Action/Adventure Comedy Drama Notice that in the following code that I use the i as in ignore the case option in the $textToSearchForMatch =~ m/WhatToMatch/i; m//i matching search pattern. So here is the search just for the Comedy category of records code, which I will handout and go over in class on Monday. # Illustrates getting just the Comedy category of records. open (MOVIES, "moviesPERL.txt"); # moviestabsplit.txt has bad ones ; %films = (); # this is an empty hash, used to get the unique movies $n = 0; while ($rec = ) { @record = (split (/\t/, $rec)); next if ( ($record[4] =~ m/drama/i) || ($record[4] =~ m/action/i) ); $n++; $movies{ $record[1] } = 1; } close MOVIES; print "\nThere were $n quotes from comedy movies.\n"; $n = 0; foreach (sort keys %movies) { $n++; print "\n $n $_"; } 4. So looking at the above, it should be easy to see that for a .cgi perl program, you would instead be doing something like: print "
    \n"; foreach (sort keys %movies) { print "
  1. $_ \n"; } print "
/n"; to send the output to a web browser client. And the FORM will have mechanism for the user of your web page to choose from either: All Movies Action/Adventure Comedy Drama You could have FOUR DIFFERENT buttons, but it would be better to use radio buttons or selection menus as your technique. The only thing you have to do is show the user the list of all of the movie names, when they click the Submit or the Show Movies button. That is all you have to do. Don't make this more complicated or difficult than it is! Once you get it working to show ALL of the 34 movie names, then add the SELECTION MENU or the Radio Buttons (option buttons) so they choose from one of: All Action Adventure Comedy Drama Mark