Skip to Main Content
Perl in a Nutshell, 2nd Edition
book

Perl in a Nutshell, 2nd Edition

by Nathan Patwardhan, Ellen Siever, Stephen Spainhour
June 2002
Beginner content levelBeginner
759 pages
80h 42m
English
O'Reilly Media, Inc.
Content preview from Perl in a Nutshell, 2nd Edition

Exporter

Implements a default import method for other modules to inherit if they don’t want to define their own. If you are writing a module, you can do the following:

package Module;
use Exporter (  );
@ISA = qw(Exporter);

@EXPORT = qw(...);              
@EXPORT_OK = qw(...);           
%EXPORT_TAGS = (tag => [...]);

in which @EXPORT is a list of symbols to export by default, @EXPORT_OK is a list of symbols to export on request, and %EXPORT_TAGS is a hash that defines names for sets of symbols. Names in %EXPORT_TAGS must also appear in @EXPORT or @EXPORT_OK.

Then Perl programs that want to use your module just say:

use Module;                   # Import default symbols
use Module qw(...);           # Import listed symbols
use Module (  );              # Do not import any symbols

The Exporter can handle specialized import lists. An import list is the list of arguments passed to the import method. If the first entry begins with !, :, or /, the list is treated as a series of specifications that add to or delete from the list. A leading ! means delete, rather than add.

Symbol

Meaning

[!] name

This name only

[!]:DEFAULT

All names in @EXPORT

[!]:tag

All names in $EXPORT_TAGS{ tag } anonymous list

[!]/ pattern /

All names in @EXPORT and @EXPORT_OK that match pattern

Exporter’s methods are the following.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl by Example, Fourth Edition

Perl by Example, Fourth Edition

Ellie Quigley
Perl Cookbook, 2nd Edition

Perl Cookbook, 2nd Edition

Tom Christiansen, Nathan Torkington
Perl in a Nutshell

Perl in a Nutshell

Nathan Patwardhan, Ellen Siever, Stephen Spainhour
Learning Perl, 7th Edition

Learning Perl, 7th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 0596002416Errata Page