Section 3.2. Using Modules


3.2. Using Modules

Almost every Perl module comes with documentation, and even though we might not know how all of the behind-the-scenes magic works, we really don't have to worry about that stuff if we know how to use the interface. That's why the interface is there, after all: to hide the details.

On our local machine, we can read the module documentation with the perldoc command. We give it the module name we're interested in, and it prints out its documentation.

 $ perldoc File::Basename NAME            fileparse - split a pathname into pieces            basename - extract just the filename from a path            dirname - extract just the directory from a path SYNOPSIS                    use File::Basename;                    ($name,$path,$suffix) = fileparse($fullname,@suffixlist)                    fileparse_set_fstype($os_string);                    $basename = basename($fullname,@suffixlist);                    $dirname = dirname($fullname); 

We've included the top portion of the documentation to show you the most important section (at least, the most important when you're starting). Module documentation typically follows the old Unix manpage format, which starts with a NAME and SYNOPSIS section.

The synopsis gives us examples of the module's use, and if we can suspend understanding for a bit and follow the example, we can use the module. That is to say, it may be that you're not yet familiar with some of the Perl techniques and syntax in the synopsis, but you can generally just follow the example and make everything work.

Now, since Perl is a mix of procedural, functional, object-oriented, and other sorts of language types, Perl modules come in a variety of different interfaces. We'll employ these modules in slightly different fashions, but as long as we can check the documentation, we shouldn't have a problem.




Intermediate Perl
Intermediate Perl
ISBN: 0596102062
EAN: 2147483647
Year: N/A
Pages: 238

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