ADBRITE ads links
You are here: CodeIdol.com > Perl > Intermediate Perl > Building Larger Programs
Intermediate Perl
| 10.1. The Cure for the Common Code
The Skipper writes many Perl programs to provide navigation for all the common ports of call for the Minnow. He finds himself cutting and pasting a very common routine into each program:
sub turn_toward_hea...
|
|
| 10.2. Inserting Code with eval
The Skipper can save disk space (and brain space) by bringing the definition for turn_toward_heading out into a separate file. For example, suppose the Skipper figures out a half-dozen common subroutines relate...
|
|
| 10.3. Using do
The Skipper placed a few common navigation subroutines into navigation.pm. If the Skipper merely inserts:
do 'navigation.pm';
die $@ if $@;
into his typical navigation program, it's almost the same as if the eval c...
|
|
| 10.4. Using require
Suppose navigation.pm itself also pulls in drop_anchor.pm for some common navigation task. Perl reads the file once directly and then again while processing the navigation package. This needlessly redefines drop_...
|
|
| 10.5. require and @INC
So far, the examples have glossed over how we've set up the directory structure of where the main code and the included files are located. That's because it "just works" for the simplest case where we have a program and its ...
|
|
| 10.6. The Problem of Namespace Collisions
Sometimes the Skipper runs a ship into an island, but sometimes the collision involved is just a couple of names in a Perl program. Suppose that the Skipper has added all his cool and useful routines...
|
|
| 10.7. Packages as Namespace Separators
If the name prefix of the last example didn't have to be spelled out on every use, things would work much better. We can improve the situation by using a package:
package Navigation;
sub turn_t...
|
|
| 10.8. Scope of a Package Directive
All files start as if we had said package main;.[*] Any package directive remains in effect until the next package directive, unless that package directive is inside a curly-braced scope. In that case, P...
|
|
| 10.9. Packages and Lexicals
A lexical variable (a variable introduced with my) isn't prefixed by the current package because package variables are always global: we can always reference a package variable if we know its full name. A lexical variab...
|
|
| 10.10. Exercises
You can find the answers to these exercises in "Answers for Chapter 10" in the Appendix.
10.10.1. Exercise 1 [25 min]
The Oogaboogoo natives on the island have unusual names for the days and months. Here is some...
|
|
You are here: CodeIdol.com > Perl > Intermediate Perl > Building Larger Programs
|
|
Related tags
Popular Categories
Unix books and guides
AJAX popular information
C# language guides
Windows books and cookbooks
.......
|
|