Module Getopt::Long - extended processing of command line options ================================================================= Module Getopt::Long implements an extended getopt function called GetOptions(). This function implements the POSIX standard for command line options, with GNU extensions, while still capable of handling the traditional one-letter options. In general, this means that command line options can have long names instead of single letters, and are introduced with a double dash `--'. Optionally, Getopt::Long can support the traditional bundling of single-letter command line options. Getopt::Long::GetOptions() is part of the Perl 5 distribution. It is the successor of newgetopt.pl that came with Perl 4. It is fully upward compatible. In fact, the Perl 5 version of newgetopt.pl is just a wrapper around the module. For complete documentation, see the Getopt::Long POD document or use the command perldoc Getopt::Long FEATURES ======== * Long option names Major advantage of using long option names is that it is much easier to memorize the option names. Using single-letter names one quickly runs into the problem that there is no logical relationship between the semantics of the selected option and its option letter. Disadvantage is that it requires more typing. Getopt::Long provides for option name abbreviation, so option names may be abbreviated to uniqueness. Also, modern shells like Cornell's tcsh support option name completion. As a rule of thumb, you can use abbreviations freely while running commands interactively but always use the full names in scripts. Examples (POSIX compliant): --long --width=80 --height=24 Extensions: -long (convenience) +width=80 (deprecated) -height 24 (traditional) By default, long option names are case insensitive. * Single-letter options and bundling When single-letter options are requested, Getopt::Long allows the option names to be bundled, e.g. "-abc" is equivalent to "-a -b -c". In this case, long option names must be introduced with the POSIX "--" introducer. Examples: -lgAd (bundle) -xw 80 (bundle, w takes a value) -xw80 (same) even -l24w80 (l = 24 and w = 80) By default, single-letter option names are case sensitive. * Flexibility: - options can have alternative names, using an alternative name will behave as if the primary name was used; - options can be negatable, e.g. "debug" will switch it on, while "nodebug" will switch it off; - options can set values, but also add values producing an array of values instead of a single scalar value, or set values in a hash; - options can have value lists and ranges of valid values associated; - options can take multiple arguments, e.g. a coordinate would require three numbers. * Option types - flags, that get set when the option occurs, e.g. "-debug"; - numeric, the specified value will be assigned, e.g. "-width 80"; - string, an arbitrary value, e.g. "-title Hello"; - boolean, something considered true e.g. "yes", or false e.g. "off". * Options linkage Using Getopt::Long gives the programmer ultimate control over the command line options and how they must be handled: - by setting a global variable in the calling program; - by setting a specified variable; - by entering the option name and the value in an associative array (hash) or object (if it is a blessed hash); - by calling a user-specified subroutine with the option name and the value as arguments; - combinations of the above. * Customization: The module contains a special method, Getopt::Long::Configure, to control configuration variables to activate (or de-activate) specific behaviour. It can be called with one or more names of configuration items like "debug", "auto_abbrev", "bundling" and "ignore_case". * Object orientation: Instead of just calling GetOptions, you can also use it in an object-oriented way: my $parser = new Getopt::Long; $parser->configure (...); # set configuration $parser->define (...); # define options $parser->parse; # parse @ARGV AVAILABILITY ============ The official version for module Getopt::Long comes with the Perl 5 distribution. Newer versions will be made available on the Comprehensive Perl Archive Network (CPAN), see "http://www.perl.com/CPAN/authors/Johan_Vromans". COPYRIGHT AND DISCLAIMER ======================== Module Getopt::Long is Copyright 1990,1998 by Johan Vromans. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ------------------------------------------------------------------- Johan Vromans jvromans@squirrel.nl Squirrel Consultancy Haarlem, the Netherlands http://www.squirrel.nl http://www.squirrel.nl/people/jvromans ------------------ "Arms are made for hugging" --------------------