1. What two operations change an array from the front or first element? 2. What two operations change an array from the last element? 3. Write the two Perl statements that would take array @a and make the 1st element into the last element. (Using #1 and #2 operations). [0] [1] [2] ----------------- For example, if @a is | 100 | 200 | 300 | before the two statements, ----------------- [0] [1] [2] ----------------- it will be | 200 | 300 | 100 | afterwards. ----------------- 4. Write the two Perl statements that would take array @a and make the last element into the first element. Using #1 and #2 operations). 5. Write the one Perl statement that would create array @numbers from the scalar variable $numberList. $numberList = "111/222/333/444"; # Assume / separates each pair... 6. In the statement that follows, what term is used to describe the digit 3? $myFavoriteMovies[3] = "Ghostbusters"; 7. In the statement that follows, what term is used to describe the word 'Ghostbusters'? print "Ghostbusters came out in " . $yearOfMovie{'Ghostbusters'}; 8. Write the statement that would create the string of colon separated values from the values in array @a. Name the variable to hold the colon separated values string $myValues. [0] [1] [2] ------------------- @a | 111 | 222 | 333 | would make $myValues string "111:222:333" ------------------- ----------- 9. Write the single Perl statement that will cause the change in variable $data contents, as illustrated below. Basically the vowels aeiou have been converted to uppercase AEIOU. $data = "abcdefghijklmnopqrstuvwxyz"; MYSTERY PERL STATEMENT GOES HERE. print $data; OUTPUT IS: AbcdEfghIjklmnOpqrstUvwxyz 10. Write the single Perl statement that will cause the change in variable $data contents, as illustrated below. $data = "UNI Panthers; oh ya, you go now! "; MYSTERY PERL STATEMENT GOES HERE. print $data; OUTPUT IS: UNIPanthersohyayougonow 11. Suppose you want to print out the words or phrases stored in array @snowBall one on each line on your web page, with a horizontal ruler underneath or below or after each word. Write the Perl code segment to do this portion of the web page. We want lots of space BEFORE and AFTER each horizontal ruler, so just use a new paragraph tag to cause that extra spacing. 12. Assume that you have called the localtime(time) function and that array @colors has values as follows: @colors = qw(YELLOW GREEN BLUE ORANGE GRAY PINK PURPLE); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$dst) = localtime(time); What statement would be used to store in the variable $BGColor the appropriate color for the day of the week, where we want Sunday to always be YELLOW, Monday to always be GREEN, etc.? 13. Finish the following program so that it does sends the web page c088.html to client browser. Assume the program is called c088colorSurprise.cgi and that it uses the function rgbValue to calculate and return two RGB triplets. The 1st is for the background color and the 2nd is for the text color. Assume that rgbValues returns an array, just like our guestBook.lib library function rgbValues does. Assume that the file c088.html has on a line all by itself, starting at the beginning of the line, the tag. Your c088colorSurprise.cgi program will send a different line to the web browser, for example: might be sent one time, and the next time, gets sent. Its all taken care of by rgbValue function, which you DO NOT have to define, you just have to use it to get the array of RGB triplets, and then use the array. #!/usr/bin/perl use CGI qw(:standard); require guestBook.lib; # <-- to have access to rgbValue function 14. Write the one statement that would be used to open a file for input in your PERL program with the file handle FILEHANDLE. Assume that the file is named question14.txt and that it is stored inside of your web folder. The cgi-bin folder is where this script is being executed from, of course. 15. Write the name or term for this operator? =~ 16. What is the term that describes something the following Perl programmer apparently did not know about or is not taking advantage of? print "Volume is " . $volume . " for cylinder with height " . $height . " and radius " . $radius; 17. What permissions should be used for your guestBook.html file? 18. What is the pico editor keystroke used to find out what line you are on for the line you are positioned on while in the editor? 19. Write the Perl statement that would execute the Unix cal command and store the results in the variable $thisMonthsCalendar. Clearly indicate the syntax of your statement for any special symbols by shaping them so they are not confused with the wrong symbol from the keyboard. 20. What is the exact output of the following program? @a = qw(This is it is this); #2 @a = qw(R A D A R); @b = @a; #3 @a = qw(M A D A M I M A D A M); $palindrome = 1; while (@a > 1) { $first = shift(@a); $last = pop(@a); if ($first ne $last) { $palindrome = 0; last; } } if ($palindrome) { print "*** @b *** is a palindrome, and so is *** @a ***\n"; } else { print "--> @b <-- is not a palindrome, but --> @a <-- might be\n"; } 21. Here is a screen snapshot of the web page displayed by the showForm.cgi Perl script. Write the showForm.cgi script. Do NOT write the calcVolume.cgi script that it calls when the user clicks the Calculate Volume submit button. That's for question 22. Name the 3 text boxes length, width and height. No upper-case letters! Calculates the volume of a box <---- BIG, BOLD LETTERS (heading style) --------------- Length: | | --------------- --------------- Width: | | --------------- --------------- Height: | | --------------- ******************** * Calculate Volume * <----- This is the SUBMIT ******************** button and it invokes calcVolume.cgi Perl script, that you write for question number 22. 22. Write the calcVolume.cgi Perl script. Remember, the names of the text boxes are assumed to be length, width and height. Notice: all lower-case letters. Your output could look like this, for a specific example: Box volume is 3000 for box with height 10, length 20 and width 15. 23. Modify the following statement (rewrite it or clearly indicate the needed changes to it), so that it does not require any use of \ characters at all. print "$friend said: \"How hot it is today?\" and I agreed $n times."; 24. Write the Perl statements to print the numbers 1 through 10 each on a separate line. Your Perl statement are to be executed from the command line and never even put into a file and saved with an editor like pico, emacs, vi or Notepad. 25. What is the Unix (chaos.cns.uni.edu) command that shows your file permissions for all files with the .html extension? 26. What Unix command would allow you to make a copy of the file colors.html named colors2.html? 27. What Unix command would help you remember what commands you have been doing recently, by listing all the recent ones on your screen? 28. A hash uses the symbol % to indicate that the Perl variable is a hash? Explain why the % symbol is perfect syntactic expression for what a hash is? Be very explicit and get into exactly what the % symbol looks like. The % character has 3 parts, 2 circles and one slash / separating the two little circles. 29. What is the output of the following 3 subroutines or functions f, g, and h Perl program? #!/usr/bin/perl -w sub f { print "\nEntered f "; return "\n f: Moe "; } sub g { print "\nEntered g "; return "\n g: Larry "; } sub h { print "\nEntered h "; return "\n h: Curly "; } print "\n\n**** Output of ----> print f, g, h; ****"; print f, g, h; print "\n\n**** Output of ----> print f, print g, print h; ****"; print f, print g, print h; print "\n\n**** Output of ----> print f; print g; print h; ****"; print f; print g; print h . "\n\n"; 30. Name the following two operators? $str = "One" . "Two"; 31. Give the THREE different ways to make sure that the $str variable output would only be lower-case letters. Your last statement in each case will be a print statement. It might be the only statement, for some or all of the i., ii., and iii. cases. $str = "Some UPPER-CASE like UNI and ABC"; i. ii. iii. 32. Write the function named ascending that would return 1 (True) if the list of numbers is sorted into ascending order, and return 0 (False) otherwise. if ( &ascending(@a) ) { $m = "is sorted"; } else { $m = "is NOT sorted"; } print "List (@a) $m into ASCENDING order.\n"; 33. What does the E in PERL stand for? 34. How many lines of output will the following program produce, if the user typed in HELLO at the ENTER DATA: prompt? Note: Do not count the ENTER DATA: prompt as a line of output. All other lines, including blank lines, count as output. #------------------------------------------------------------------ print "ENTER DATA: "; $data = ; # User typed in HELLO. (SEE NOTE ABOVE!) while (length $data > 0) { print $data . "\n"; chop $data; } print "\n ----------------- \nThat is all for this program! \n"; #------------------------------------------------------------------ 34. Show the exact output of the above program, in question #33. 35. What does whipupitude refer to in regard to Perl and Larry Wall, its creator? 36. a. How many times does the print substr() statement get executed for the following program? b. What is the exact output of the following program? $panthers = "UNIPanthers"; for ($i = 0; $i <= 3; $i++) { print substr($panthers, $i, $i + 1) . "\n"; } 37. What is the output of the following remainder calculating program? Recall that the % is the remainder or mod operator. For example: (87 % 20) gives the value 7, since 87 divided by 20 gives a remainder of 7. for ($i = 10; $i <= 90; $i += 10) { print "\n $i \% 7 ---> " . $i % 7 . "\n"; } 38. Now, lets combine questions #36 and #37 and try to figure out what the output of the following combination of for loops, the % operator and the substr() function would be. What is the output of the following? $panthers = "UNIPanthers"; for ($i = 0; $i <= 7; $i++) { print substr($panthers, $i, ($i % 4) + 1) . "\n"; } 39. What is the output of this Perl program? $panthers = "PANTHERS"; for ($i = length $panthers; $i >= 1; $i--) { print substr($panthers, $i - 1, 1) . "\n"; } 40. What is the output of the following Perl program? $sentence1 = "i am the snow white disney workers wondered curiously"; $sentence2 = "a ma bee flew dance waggle quickly westward"; @words = split (/ /, $sentence2); foreach $w (@words) { print " $w \n"; }