1 Module Getopt::Long - extended processing of command line options
2 =================================================================
4 Module Getopt::Long implements an extended getopt function called
5 GetOptions(). This function implements the POSIX standard for command
6 line options, with GNU extensions, while still capable of handling
7 the traditional one-letter options.
8 In general, this means that command line options can have long names
9 instead of single letters, and are introduced with a double dash `--'.
11 Optionally, Getopt::Long can support the traditional bundling of
12 single-letter command line options.
14 Getopt::Long is part of the Perl 5 distribution. It is the successor
15 of newgetopt.pl that came with Perl 4. It is fully upward compatible.
16 In fact, the Perl 5 version of newgetopt.pl is just a wrapper around
19 For complete documentation, see the Getopt::Long POD document or use
29 Major advantage of using long option names is that it is much easier
30 to memorize the option names. Using single-letter names one quickly
31 runs into the problem that there is no logical relationship between
32 the semantics of the selected option and its option letter.
33 Disadvantage is that it requires more typing. Getopt::Long provides
34 for option name abbreviation, so option names may be abbreviated to
35 uniqueness. Also, modern shells like Cornell's tcsh support option
36 name completion. As a rule of thumb, you can use abbreviations freely
37 while running commands interactively but always use the full names in
42 --long --width=80 --height=24
46 -long (convenience) +width=80 (deprecated) -height 24 (traditional)
48 By default, long option names are case insensitive.
50 * Single-letter options and bundling
52 When single-letter options are requested, Getopt::Long allows the
53 option names to be bundled, e.g. "-abc" is equivalent to "-a -b -c".
54 In this case, long option names must be introduced with the POSIX "--"
59 -lgAd (bundle) -xw 80 (bundle, w takes a value) -xw80 (same)
60 even -l24w80 (l = 24 and w = 80)
62 By default, single-letter option names are case sensitive.
66 - options can have alternative names, using an alternative name
67 will behave as if the primary name was used;
68 - options can be negatable, e.g. "debug" will switch it on, while
69 "nodebug" will switch it off.
70 - options can set values, but also add values producing an array
71 of values instead of a single scalar value, or set values in a hash.
72 - options can have multiple values, e.g., "--position 25 624".
76 Using Getopt::Long gives the programmer ultimate control over the
77 command line options and how they must be handled:
79 - by setting a global variable in the calling program;
80 - by setting a specified variable;
81 - by entering the option name and the value in an associative array
82 (hash) or object (if it is a blessed hash);
83 - by calling a user-specified subroutine with the option name and
84 the value as arguments (for hash options: the name, key and value);
85 - combinations of the above.
89 The module can be customized by specifying settings in the 'use'
90 directive, or by calling a special method, Getopt::Long::Configure.
91 For example, the following two cases are functionally equal:
93 use Getopt::Long qw(:config bundling no_ignore_case);
98 Getopt::Long::Configure qw(bundling no_ignore_case);
100 Some of the possible customizations. Most of them take a "no_" prefix
101 to reverse the effect:
105 Restore default settings.
109 Allow option names to be abbreviated to uniqueness.
113 Allow '+' to start options.
117 Compatibility with GNU getopt_long().
122 Whether non-options are allowed to be mixed with options.
126 -foo arg1 -bar arg2 arg3
130 -foo -bar arg1 arg2 arg3
132 (provided -foo does not take an argument value).
134 require_order means that options processing
135 terminates when the first non-option is encountered.
137 -foo arg1 -bar arg2 arg3
141 -foo -- arg1 -bar arg2 arg3
145 Setting this variable to a non-zero value will allow
146 single-character options to be bundled. To distinguish bundles
147 from long option names, long options must be introduced with
148 "--" and single-character options (and bundles) with "-".
152 Ignore case when matching options.
156 Do not issue error messages for unknown options, but leave
157 them (pass-through) in @ARGV.
161 The string that starts options. See also prefix_pattern.
165 A Perl pattern that identifies the strings that introduce
166 options. Default is --|-|\+ unless environment variable
167 POSIXLY_CORRECT has been set, in which case it is --|-.
169 - long_prefix_pattern
171 A perl pattern that is used to identify which prefixes
172 should be treated as long style. Any prefixes that don't
173 match this pattern will have short option semantics.
178 Enable copious debugging output.
180 * Object oriented interface:
182 Using the object oriented interface, multiple parser objects can be
183 instantiated, each having their own configuration settings:
185 $p1 = new Getopt::Long::Parser (config => ["bundling"]);
186 $p2 = new Getopt::Long::Parser (config => ["posix"]);
187 if ($p1->getoptions(...options descriptions...)) ...
192 The official version for module Getopt::Long comes with the Perl 5
194 Newer versions will be made available on the Comprehensive Perl Archive
195 Network (CPAN), see "http://www.perl.com/CPAN/authors/Johan_Vromans".
196 Or use the CPAN search engine:
197 http://search.cpan.org/search?mode=module&query=Getopt::Long
198 http://search.cpan.org/search?module=Getopt::Long
200 COPYRIGHT AND DISCLAIMER
201 ========================
203 Module Getopt::Long is Copyright 2006,1990 by Johan Vromans.
204 This program is free software; you can redistribute it and/or
205 modify it under the terms of the Perl Artistic License or the
206 GNU General Public License as published by the Free Software
207 Foundation; either version 2 of the License, or (at your option) any
210 -------------------------------------------------------------------
211 Johan Vromans jvromans@squirrel.nl
212 Squirrel Consultancy Exloo, the Netherlands
213 http://www.squirrel.nl http://www.squirrel.nl/people/jvromans
214 ------------------ "Arms are made for hugging" --------------------