Chapter 2
If you place the preceding code in a file called Hello.pm, then you can use the module
in a script placed in the same directory as Hello.pm:
#!/usr/bin/perl
use lib . ;
use Hello;
Hello::greet("World");
This produces the following output:
Hello, World!
Most of the code example should look familiar, but the use lib line might be new.
I'll explain that in the next section.
...........................................................................................................................................................................................................................
Module Names
A module's name is its introduction. If you choose good names for your modules,
you'll rarely have to answer the question What does it do? For example, pro
grammers rarely ask me what HTML::Template does, but HTML::Pager draws
inquiries on every mention.
Perl modules must have unique names. Having two modules with the same
name will cause difficulties. This is similar to machines on the Internet if there
were two Web sites called http://www.cpan.org, how would a browser know
where to send you?
7
An easy solution to the problem of finding a unique name is to use a multipart
name. Module names can be composed of parts delimited by double colons
(::). Most modules have names with two parts and some have three Inline::C,
Scalar::List::Utils, Parse::RecDescent, CGI::Application. Following this practice is
a good idea it keeps your module names short enough to easily remember. If
you do use a long name, then you should be careful to choose a name within a
hierarchy that will make it easy for others to find.
Many organizations use a common prefix for all their internal modules. For
example, Vanguard Media (http://www.vm.com) creates their internal modules
under the name Dynexus Dynexus::Template::File, Dynexus::Class::Base,
and so on. This keeps the internal modules names from conflicting with names
of externally produced modules. If you are creating private modules, you should
consider a similar naming convention.
7. Ok, bad example round robin DNS works using this technique, but you get my point.
28
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved