start page | rating of books | rating of authors | reviews | copyrights

Book Home Programming PerlSearch this book

Chapter 32. Standard Modules

Contents:

Listings by Type
Benchmark
Carp
CGI
CGI::Carp
Class::Struct
Config
CPAN
Cwd
Data::Dumper
DB_File
Dumpvalue
English
Errno
Exporter
Fatal
Fcntl
File::Basename
File::Compare
File::Copy
File::Find
File::Glob
File::Spec
File::stat
File::Temp
FileHandle
Getopt::Long
Getopt::Std
IO::Socket
IPC::Open2
IPC::Open3
Math::BigInt
Math::Complex
Math::Trig
Net::hostent
POSIX
Safe
Socket
Symbol
Sys::Hostname
Sys::Syslog
Term::Cap
Text::Wrap
Time::Local
Time::localtime
User::grent
User::pwent

The previous edition of this book included comprehensive, definitive coverage for all modules that were part of the standard Perl distribution. But if we did that again now, you'd pay twice what you're paying for this book, not to mention what you'd have to pay the chiropractor after trying to carry the book home. Over the last few years, more and more modules have come bundled standard; we're up to around two hundred of them right now. Some of these, such as CGI, have remarkably extensive documentation in their own right. And if you're using ActiveState's distribution of Perl, your standard library is even more luxed out.

So instead, we provide a complete listing of the standard modules, sorted by type, along with a brief description of what each module does. Then we cherry pick a few of our favorite modules by providing examples of typical uses, followed by a short description of how they work, just to give you a taste of using them. The descriptions are suggestive rather than comprehensive, and virtually all the modules have features beyond those shown. However, complete documentation for all standard modules is included with every Perl distribution, so you can just look up the details on your own system using the perldoc program, your system's man(1) command, or your favorite browser. See the section "Online Documentation" in the Preface. Ask your Local Expert if you can't find the docs, because they're almost certainly installed somewhere on your system. Even if they're not, you can always read the pod docs directly from the modules themselves, because all module docs come embedded in their corresponding module (.pm) files, and pod was designed to be somewhat readable. (Unlike, say, HTML.)

32.1. Listings by Type

Normal module names begin with an uppercase letter. Lowercase names indicate pragmas that you'll find documented in Chapter 31, "Pragmatic Modules", rather than in this chapter.

32.1.1. Data Types

These modules extend Perl's type system (or lack thereof) in various ways.

Module Description
Class::Struct

Create struct-like Perl object classes

constant

Declare constant scalars and lists

integer

Force Perl to do arithmetic with integers instead of floating point

Math::BigFloat

Calculate with arbitrary length floating-point math

Math::BigInt

Calculate with arbitrary length integer math

Math::Complex

Calculate with complex numbers and associated mathematical functions

Math::Trig

Load many trigonometric and related functions

overload

Overload Perl operators on objects

Symbol

Manipulate Perl symbol tables and generate anonymous typeglobs

Time::Local

Efficiently compute epoch time given localtime or gmtime

32.1.2. String Processing, Language Text Processing, Parsing, and Searching

These modules do things with (or to) text.

Module Description
Search::Dict

Use a binary search for a string in a sorted text file

Text::Abbrev

Create an abbreviation table from a list

Text::ParseWords

Parse text into a list of tokens or an array of arrays

Text::Soundex

Use Knuth's Soundex algorithm

Text::Tabs Expand or unexpand tabs like expand (1) and unexpand (1)
Text::Wrap

Wrap lines to form simple paragraphs

32.1.3. Option, Argument, Parameter, and Configuration File Processing

These modules process your command line.

Module Description
Getopt::Long Process extended command-line options in long form (--xxx)
Getopt::Std

Process single-character switches with switch clustering (-xyz)

32.1.4. Filenames, Filesystems, and File Locking

These modules provide cross-platform methods of file access.

Module Description
Cwd

Get the pathname of the current working directory

File::Basename

Portably parse a pathname into directory, basename, and extension components

File::CheckTree

Run many file test checks on a set of directory trees

File::Compare

Portably compare contents of filenames or filehandles

File::Copy

Portably copy filenames or filehandles or move filenames

File::DosGlob

Do Microsoft-style fileglobbing

File::Find

Traverse a file tree like find(1)

File::Glob

Use Unix-style fileglobbing

File::Path

Portably create or remove a series of directories

File::Spec Use portable filename operations (object-oriented interface)
File::Spec::Functions

Use portable filename operations (functional interface)

File::Spec::Mac

Use filename operations for Mac OS files

File::Spec::OS2

Use filename operations for OS/2 files

File::Spec::Unix

Use filename operations for Unix files

File::Spec::VMS

Use filename operations for VMS files

File::Spec::Win32

Use filename operations for Microsoft files

File::stat

Override built-in stat and lstat functions with a method interface

32.1.5. Filehandle, Directory Handle, and Stream I/O Utilities

These modules provide object-oriented file, directory, and IPC access.

Module Description
DirHandle

Use object methods for directory handles

FileCache

Keep more files concurrently open for output than your system permits

FileHandle

Use object methods for filehandles

IO

Provide a frontend to load all of IO::Dir, IO::File, IO::Handle, IO::Pipe, IO::Seekable, and IO::Socket

IO::Dir

Use object methods for directory handles

IO::File

Use file-related object methods for filehandles

IO::Handle

Use generic object methods for filehandles

IO::Pipe

Use object methods for pipes

IO::Poll

Provide an object interface to poll(2) syscall

IO::Seekable

Use object methods for seekable I/O objects

IO::Select

Use a convenient OO interface to the select(2) syscall

SelectSaver

Save and restore selected filehandle

32.1.6. Internationalization and Locale

These modules help you perform Un-American Activities.

Module Description
bytes

Enforce old byte-oriented semantics

charnames

Define character names used in \N{name} escapes in string literals

I18N::Collate

Compare 8-bit scalar data according to current locale (deprecated)

locale

Use or avoid POSIX locales for built-in operations

utf8

Turn on UTF-8 and Unicode support explicitly

32.1.7. Operating System Interfaces

These modules tweak your interface to the operating system.

Module Description
Fcntl

Load the C library's fcntl.h definitions as Perl constants

filetest

Control the file test operators (-r, -w, etc.) for nontraditional filesystems

open

Set default disciplines for open function calls

POSIX

Use the Perl interface to POSIX 1003.1

Shell

Run shell commands transparently within Perl

sigtrap

Enable simple signal handling

Sys::Hostname

Portably try every conceivable way to determine the current hostname

Sys::Syslog

Use the C library's syslog(3) functions

Time::gmtime

Override the built-in gmtime function with a method interface

Time::localtime

Override the built-in localtime function with a method interface

Time::tm

Provide the internal object used by Time::gmtime and Time::localtime

User::grent

Override built-in getgr* functions with a method interface

User::pwent

Override built-in getpw* functions with a method interface

32.1.8. Networking and Interprocess Communication

These modules provide abstract interfaces around the basic interfaces we wrote about in Chapter 16, "Interprocess Communication".

Module Description
IO::Socket

Use a generic object interface to socket communications

IO::Socket::INET

Use an object interface for Internet-domain sockets

IO::Socket::UNIX

Use an object interface for Unix-domain (local) sockets

IPC::Msg

Use object methods for working with System V messages (SysV Msg IPC object class)

IPC::Open2

Open a process for simultaneous reading and writing

IPC::Open3

Open a process for reading, writing, and error handling

IPC::Semaphore

Use object methods for System V semaphores

IPC::SysV

Define constants for all System V IPC mechanisms

Net::hostent

Override built-in gethost* functions with a method interface

Net::netent

Override built-in getnet* functions with a method interface

Net::Ping

Check a remote host for reachability

Net::protoent

Override built-in getproto* functions with a method interface

Net::servent

Override built-in getserv* functions with a method interface

Socket

Load the C library socket.h definitions and structure manipulators

32.1.9. World Wide Web

These modules interface to the WWW. You may have heard of it.

Module Description
CGI

Access CGI forms and powerful automated HTML generation

CGI::Apache

Make your CGI script work under the Perl-Apache API

CGI::Carp

Write to the httpd(8) (or other) CGI error log

CGI::Cookie

Set and get HTTP cookies

CGI::Fast

Use the Fast CGI protocol

CGI::Pretty

Produce nicely formatted HTML code

CGI::Push

Do server-push CGI scripting

32.1.10. DBM Interfaces

These modules load various database management libraries.

Module Description
AnyDBM_File

Provide a framework for multiple DBM libraries

DB_File

Provide tied access to the db(3) library (version 1.x Berkeley DB)

GDBM_File

Provide tied access to the gdbm(3) library

NDBM_File

Provide tied access to the ndbm(3) library

SDBM_File

Provide tied access to SDBM (simple DBM) files

32.1.11. User Interfaces

These modules provide a decent OS CLI I/O API, ASAP.

Module Description
Term::Cap

Use the termcap(3) library

Term::Complete

Do programmable command completion on word lists

Term::ReadLine

Use any of several readline packages

32.1.12. Authentication, Security, and Encryption

These modules work with sandboxes.

Module Description
Opcode

Enable or disable named opcodes when compiling Perl code for use with the Safe module

ops

Restrict unsafe operations when compiling

Safe

Compile and execute code in restricted compartments

32.1.13. Perl Language Extensions and Internals

(Not to be confused with Intentions and Externals.)

Module Description
attributes

Get or set subroutine or variable attributes

attrs

Get or set subroutine or variable attributes (obsolete)

base

Establish inheritance of base class at compile time

Data::Dumper

Serialize Perl data structures

DB

Access the Perl debugger's experimental API

Devel::DProf

Profile a Perl program's execution

Devel::Peek

Load data debugging tools for XS programmers

diagnostics

Force verbose warnings and suppress duplicates

Dumpvalue

Provide screen dump of data

English

Use longer variable names for built-in punctuation variables

Env

Access environment variables in %ENV as regular scalars

Errno

Load the C library's errno.h definitions and tie the %! variable

Fatal

Replace built-ins with versions that raise exceptions on failure

fields

Declare compile-time verified access to a class's data attributes

less

Request less of something from Perl (unimplemented)

re

Alter default regular expression behavior

strict

Restrict sloppy constructs

subs

Predeclare the subroutine names in current the package

vars

Predeclare global variables (obsolete--see our in Chapter 29, "Functions")

32.1.14. Convenient Classes

These modules provide base classes and other conveniences.

Module Description
Tie::Array

Provide a base class for tied arrays

Tie::Handle

Provide base class definitions for tied handles

Tie::Hash

Provide base class definitions for tied hashes

Tie::RefHash

Provide references as hash keys

Tie::Scalar

Provide base class definitions for tied scalars

Tie::SubstrHash

Hash a fixed-size table with a fixed-length key

UNIVERSAL

Provide a base class for all classes (blessed references)

32.1.15. Warnings and Exceptions

What to do when things go rwong.

Module Description
Carp

Provide routines that warn and die from the perspective of the caller

warnings

Control warnings within the lexical scope

32.1.16. Documentation Support

And there's an awful lot of documentation to support.

Module Description
Pod::Checker

Check pod documents for syntax errors (used by podchecker(1))

Pod::Functions

List built-in functions by type

Pod::Html

Convert pod files to HTML (used by pod2html(1))

Pod::InputObjects

Manage documentation support

Pod::Man

Convert pod to troff(1) format for the man(1) system (used by pod2man(1))

Pod::Parser

Provide a base class for creating pod filters and translators

Pod::Select

Extract selected sections of pod from input (used by podselect(1))

Pod::Text

Convert pod data to formatted ASCII text (used by pod2text(1))

Pod::Text::Color

Convert pod data to formatted ASCII text with ANSI color escapes

Pod::Text::Termcap

Convert pod data to ASCII text with terminal-specific escapes

Pod::Usage

Print a usage message derived from embedded pod documentation

32.1.17. Module Installation Support

These modules help other modules jump through various hoops.

Module Description
AutoLoader

Load subroutines only on demand

AutoSplit

Split a package for autoloading

autouse

Postpone module loading until a function is used from that module

blib

Use the library from MakeMaker's uninstalled version of an extension

Config

Access Perl configuration information

CPAN

Query, download, and build Perl modules from CPAN sites

Devel::SelfStubber

Generate stubs for a module using SelfLoader

DynaLoader

Dynamically load C or C++ libraries as Perl extensions

Exporter

Implement default import method for traditional modules

ExtUtils::Command

Provide utilities to replace common external commands in Makefile

ExtUtils::Embed

Provide utilities for embedding Perl in C or C++ programs

ExtUtils::Install

Install files into the system's Perl library

ExtUtils::Installed

Manage inventory of installed modules

ExtUtils::Liblist

Determine which libraries to use and how to use them

ExtUtils::MakeMaker

Create a Makefile for a Perl extension

ExtUtils::Manifest

Load tools to write and check a MANIFEST file

ExtUtils::Miniperl

Write the C code for perlmain.c

ExtUtils::Mkbootstrap

Create a bootstrap file for use by DynaLoader

ExtUtils::Mksymlists

Write linker options files for dynamic extension

ExtUtils::MM_Cygwin

Override Unix behavior methods in ExtUtils::MakeMaker

ExtUtils::MM_OS2

Override Unix behavior methods in ExtUtils::MakeMaker

ExtUtils::MM_Unix

Provide methods used by ExtUtils::MakeMaker

ExtUtils::MM_VMS

Override Unix behavior methods in ExtUtils::MakeMaker

ExtUtils::MM_Win32

Override Unix behavior methods in ExtUtils::MakeMaker

ExtUtils::Packlist

Manage .packlist files

ExtUtils::testlib

Add blib/* directories to @INC

FindBin

Locate installation directory of the Perl program that is running

lib

Manipulate @INC at compile time

SelfLoader

Load functions only on demand

XSLoader

Dynamically load C or C++ libraries as Perl extensions

32.1.18. Development Support

These modules are for timing and testing, to see how much faster and cleaner your code doesn't run anymore.

Module Description
Benchmark

Compare running times of alternate code versions

Test

Use a simple framework for writing test scripts

Test::Harness

Run standard test scripts with statistics

32.1.19. Perl Compiler and Code Generator

These modules support various backend code generators for Perl.

Module Description
B

Load Perl code generators (a.k.a. the "Perl compiler")

B::Asmdata

Provide autogenerated data about Perl ops to produce bytecode

B::Assembler

Assemble Perl bytecode

B::Bblock

Walk basic blocks in the syntax tree

B::Bytecode

Use the Perl compiler's bytecode backend

B::C

Use the Perl compiler's C translation backend

B::CC

Use the Perl compiler's optimized C translation backend

B::Debug

Walk the Perl syntax tree, printing debug info about ops

B::Deparse

Use the Perl compiler backend to reproduce Perl code

B::Disassembler

Disassemble Perl bytecode

B::Lint

Catch dubious constructs

B::Showlex

Show lexical variables used in functions or files

B::Stash

Show what stashes are loaded

B::Terse

Walk the Perl syntax tree, printing terse info about ops

B::Xref

Generate cross-reference reports for Perl programs

ByteLoader

Load byte-compiled Perl code

O

Provide a generic interface to Perl compiler backends

32.1.20. Microsoft-Related Modules

If you got the Perl distribution for Microsoft systems from ActiveState, you already have the following Microsoft-only modules included for you. If you just grabbed the standard source distribution (maybe you want to build it under the Cygwin Unix-emulation environment) but you're running on Wintel, you can get all of these modules from CPAN.

Module Description
Win32::ChangeNotify

Monitor events related to files and directories

Win32::Console

Use Win32 console and character mode functions

Win32::Event

Use Win32 event objects from Perl

Win32::EventLog

Process Win32 event logs from Perl

Win32::File

Manage file attributes in Perl

Win32::FileSecurity

Manage FileSecurity Discretionary Access Control Lists in Perl

Win32::IPC

Load the base class for Win32 synchronization objects

Win32::Internet

Access WININET.DLL functions

Win32::Mutex

Use Win32 mutex objects from Perl

Win32::NetAdmin

Manage network groups and users in Perl

Win32::NetResource

Manage network resources in Perl

Win32::ODBC

Use ODBC Extension for Win32

Win32::OLE

Use OLE automation extensions

Win32::OLE::Const

Extract constant definitions from TypeLib

Win32::OLE::Enum

Use OLE Automation Collection Objects

Win32::OLE::NLS

Use OLE National Language Support

Win32::OLE::Variant

Create and modify OLE VARIANT variables

Win32::PerfLib

Access the Windows NT Performance Counter

Win32::Process

Create and manipulate processes

Win32::Semaphore

Use Win32 semaphore objects

Win32::Service

Manage system services

Win32::Sound

Play with Windows sounds

Win32::TieRegistry

Mung the registry

Win32API::File

Access low-level Win32 system API calls for files and directories

Win32API::Net

Manage Windows NT LanManager accounts

Win32API::Registry

Access low-level Win32 system API calls from WINREG.H



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.