Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

Workshop

Quiz

1:Given the following code, what's left in @A afterward:
@A=qw(oats peas beans);
shift @A;
push @A, "barley";
pop;

  1. oats peas beans

  2. beans barley

  3. peas beans barley

2:What does printf("%18.3f", $a) do?
  1. It prints a floating-point number that is 18 characters wide, 15 to the left and 3 to the right of the decimal point.

  2. It prints a floating-point number 18 characters to the left of the decimal, a decimal point, and then 3 more digits.

  3. It prints a floating-point number that is 18 characters wide, 14 to the left and 3 to the right of the decimal point.

3:If tr/a–z/A–Z/ is run against a string, will tr/A–Z/a–z/ restore the string to its original form?
  1. Yes, of course

  2. Probably not

Answers

A1: c. The shift removed oats, and the push added barley to the end. The final pop was a ruse: No array was specified, so it popped something from the array @_, which causes nothing to happen to @A.
A2: c. If you guessed a, you didn't count the decimal point, which occupies a position in the total (18=14+1+3).
A3: b. The string "Rosebud" transformed by tr/a-z/A-Z/ becomes "ROSEBUD". Trying to transform it back with tr/A–Z/a–z/ yields "rosebud"—not the original string.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint