Date: Friday, 02 Aug 2002 06:46 AM From: Mark Jacobson To: 810-088-06@uni.edu Subject: Choosing whether to KEEP a record or not hints... This should help alot for the selecting records part of the application. You might want to get your web application working without even worrying about selecting records, and just displaying all 34 movies and all quotes from each movie. After that is working, then you can deal with developing and adding ----- the code to handle when the user gives a criteria, like Z or ee or Comedy or Murray or Vivian or Julia Robers or whatever. And of course checks one or more of the five checkboxes. # # # # # # HowToKeep.txt - August 2nd, 2002 1. When do you keep a record instead of throwing it away and not storing it in an array, for future printing? Or when decide whether to print a record or not and keep it in the report that you are making with your PERL/CGI script and sending to the client? a. If the textbox is empty, that means the user does not have any criteria, and the user wants to see ALL movies. b. If the textbox is NOT empty, the user wants to see only the records that contain the specified string (case insensitive) in one or more of the specified fields (the checkbox group). 2. Using a flag variable is a classic technique in the situation we are facing: a. $keep = 0; # set the flag to 0, i.e. to FALSE b. check each of and all of the data items for the specified criteria. In this case we are checking each one of the specified fields (from the checkboxes that are checked, possibly all 5 of them, but more likely just one or several of them. if the criteria is matched on a data item (say field 0, the movie quote), set $keep = 1 which flags this record as containing the criteria). c. if $keep == 0 then you do the following: either place the record into an array, after joining it together by TABS again. later in your program, this array will be used and needed to produce the output, or handle the output to the web page right now, by appending to the $nestedListOutput variable or having print statements send this record's output to the client browser right now. The above is the 3 steps of an algorithm. a. step one initialize the flag to false $keep = 0; b. step two go through the param{'fields') specified fields of the current record, changing $keep to 1, to true, if you find a =~ m/$pattern/i case insensitive match to occur on the contents of that field. c. step three if $keep is true, i.e. $keep == 1 then keep the record for the web page output and the nested OL and UL report, and then later on report it with your print statement(s). See this URL again now: http://student.cns.uni.edu/~venkman/cgi-bin/searchCBout.txt The array @a could be a movies database single record containing 12 different fields. Imagine we have the director, the year the movie came out, the $ the movie made, the company that made the movie (Warner Brothers), the supporting actress, the supporting actor in addition to our usual 5 fields. The example illustrates searching that single movie record for occurrences of the specified $pattern that came from the FORM, i.e. whatever the param() CGI function returned when param('usersPattern') was specified in: $pattern = param('userPattern'); I just thought of another way to do it using array slicing. Recall in PERL the TIM TOW TDI = TIM There Is More TOW Than One Way TDI To Do It I will put the 2nd way to do it below the code. Be sure to also go to the URL http://student.cns.uni.edu/~venkman/cgi-bin/searchCBout.txt or your handout which contains searchCBout.txt PERL code. # Written on July 30th, 2002 by Mark Jacobson # Testing out techniques for the movie searching specified fields # problem and application. @a = qw(zero one two three four five six seven eight nine ten eleven); print "\n--- Enter the index string, separated by colons: "; $search = <>; chomp $search; @s = split (/:/, $search); print "--- Enter your pattern please: "; $pattern = <>; chomp $pattern; foreach (@s) { if ($a[$_] =~ m/$pattern/i) { print "$pattern found in $a[$_]\n"; } } ################################################################## venkman@bebop:~/web/cgi-bin$ perl searchCheckbox.p --- Enter the index string, separated by colons: 0:1:2:3:4:5:6:7:8:9:10:11 --- Enter your pattern please: i i found in five i found in six i found in eight i found in nine venkman@bebop:~/web/cgi-bin$ perl searchCheckbox.p --- Enter the index string, separated by colons: 0:2:4:6:8 --- Enter your pattern please: i i found in six i found in eight venkman@bebop:~/web/cgi-bin$ perl searchCheckbox.p --- Enter the index string, separated by colons: 0:1:2:3:4:5:6:7:8:9:10:11 --- Enter your pattern please: ee ee found in three