Workshop

 <  Day Day Up  >  

Quiz

1:

To open a file named data for writing, you should use which of the following:

  1. open(FH, "data", write);

  2. open(FH, "data"); and simply print to FH

  3. open(FH, ">data") die "Cannot open data: $!";

2:

(-M $file > 1 and -s $file) is true if

  1. $file has been modified more than one day ago and has data.

  2. That expression cannot be true.

  3. $file is writeable and has no data.

Answers

A1:

c. Choice a is false because this is not how open opens a file for writing; b is false because it opens the filehandle only for reading. Choice c is true because it does what is asked ”and uses good form by checking for errors.

A2:

a. “M returns the number of days old a file is (>1 is more than 1 day), and “s returns true if the file has data in it.

Activities

  • Modify the Hangman program from Hour 4, "Stacking Lists and Arrays," to take the list of possible words from a data file.

 <  Day Day Up  >  


SAMS Teach Yourself Perl in 24 Hours
Sams Teach Yourself Perl in 24 Hours (3rd Edition)
ISBN: 0672327937
EAN: 2147483647
Year: 2005
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net