The Perl ‘use’ Statement
The 'use' statement in Perl fulfils two roles. Firstly, it is used to apply compiler directives at compile time. The 'strict' and 'warnings' directives were briefly mentioned previously to make Perl more robust. The 'strict' directive enforces strict variable declaration rules, whilst the 'warnings' directive enables helpful warnings.
use strict; use warnings;
The second role of the 'use' statement is to import functionality from Perl modules. As the Perl programming language contains a vast array of functionality, it is split up into modules. The benefit of this is that a Perl program need only include the modules that contains the functionality it requires to run and nothing more. The 'File::Copy' module, for example, contains functionality to copy and move files.
use File::Copy;
Below is a list containing other examples of useful modules.
- Encode - Contains character encoding functionality.
- File::Find - Provides a means to traverse a directory tree.
- File::Path - Allows for the creation and removal of directory trees.
- Math::Complex - Includes complex number and associated mathematical functionality.
- Net::FTP - Incorporates FTP client functionality.
- Net::Ping - Allows the reachability of a remote host to be verified.
- Net::Time - Includes a network client interface for time and daytime.
- Sys::Hostname - Allows for the retrieval of a hostname.
- Test - Contains a simple framework for writing test scripts.
- Time::Local - Provides a means to efficiently compute time from local and GMT time.