Workshop

 <  Day Day Up  >  

Quiz

1:

If there is no package declaration in a Perl program or module, what namespace will subroutines and package variables wind up in?

  1. main

  2. perl

  3. They're not in a package; they're lexical

2:

Which of the following is a valid way to end a module?

  1. -1;

  2. "Hello, World!"

  3. return 1;

  4. All of the above

  5. None of the above

3:

If you export a subroutine name from a module into a program that already has a subroutine by that same name , which one runs when you call the subroutine? ( Try it and see. )

  1. The subroutine from the module

  2. The subroutine from the main program

  3. Neither; the program won't compile.

  4. Neither; the program will compile, but it will crash when you call the ambiguous function.

Answers

A1:

a. Generally, anything not declared with my , and not following a package declaration, is in the namespace main .

A2:

d. All of the above. In Perl, a module must end in a statement that has a true value. The only false values in Perl are zero, undef , and the empty string. The traditional way is with 1; .

A3:

b. All use statements are processed during compile-time. Momentarily, the module's subroutine would have taken precedence. Later in the compilation it is replaced with the local version of the subroutine.

Activities

  • Expand on the File Information module to include subroutines to return the type of file (text or binary), the contents of the file (as an array), and the directory name of the file if available. This module will be revisited in the next hour , so choose good extensions.

 <  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