Документация
HTML CSS PHP PERL другое

Workshop

 
Previous Table of Contents Next

Workshop

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.

    Previous Table of Contents Next
    © 2000- NIV