NAME
Getopt::Casual - A casual replacement for other Getopt modules and -s
.
SYNOPSIS
use Getopt::Casual;
print $_, ' = ', $ARGV{ $_ }, "\n" for keys %ARGV
if $ARGV{ '--demo' };
(see F<example.pl>)
#-- Using import() to create casual defaults.
perl C<->e 'use Getopt::Casual qw/ --debug=2 C<-l> C<-t> /;
print "$_ = $ARGV{ $_ }\n" for keys %ARGV' C<-t> foo
--debug = 2
-t = foo
-l = 1
DESCRIPTION
The Getopt::Casual module simplifies the manipulation of command line arguments in what should be a familiar way to most UNIX command line utility users. The following basic rules explain the assumptions that the &casual()
makes for either &import()
or @ARGV
command line processing:
1) Arguments can be single characters or and combination of
characters, although depending on your shell, some characters will
be interpreted by the shell.
2) Arguments that begin with a '-' followed by another item in
@ARGV, which can include spaces if the string is enclosed by
quotes or double quotes, will have the value of that string.
See Rule 3.
3) Arguments that begin with a '-' followed by another argument in
@ARGV that begins with a '-', including quoted strings that
contain spaces, will have a value of 1.
4) Arguments that do not begin with a '-' will have a value of one.
When preceded by an odd number of arguments that begin with a dash,
this string is a value of the previous command line argument.
5) Arguments that begin with a '--' have a value of one. (See Rule 7)
6) The string '--' will terminate command line processing.
7) If the string contains an '=', the part of the string preceding
the first '=' will be a key of %ARGV and the value will be the
part following the first '=' until the end of that element of @ARGV.
8) All arguments of the script can be found as either a key or a
value of %ARGV.
9) @ARGV will contain only the arguments that meet the following criteria.
a) All arguments after a '--' will be contained in @ARGV unless
one of the next two criteria are met first.
b) All arguments after the last occurance of an argument that
begins with a '-' and that arguments value.
-OR-
All arguments after the last occurance of an argument that
contains an '='.
The same set of rules apply to the arguments you pass the import() subroutine.
EXAMPLES
See the included program called example.pl.
BUGS
If you find one, please tell me or supply a patch.
SEE ALSO
NOTES
There has been some doubt as to whether or not this was useful enough to have to remember to tote it with you to every system on which you had command line perl scripts. The obvious advantage of the core modules is that they are wherever perl is installed. If portablity is really a key issue, use the core modules.
AUTHOR
Daniel M. Lipton <photo@tiac.net>
Contributors
Patrick M. Jordan <patrick@antistatic.com> Ronald J. Kimball <rjk@linguist.dartmouth.edu> Andrew N. Hicox <Andrew N. Hicox>