.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "CIL::Mixed 3pm" .TH CIL::Mixed 3pm "2018-09-09" "perl v5.26.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Getopt::Mixed \- [OBSOLETE] getopt processing with both long and short options .SH "VERSION" .IX Header "VERSION" This document describes version 1.12 of Getopt::Mixed, released February 8, 2014. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use Getopt::Mixed; \& Getopt::Mixed::getOptions(...option\-descriptions...); \& ...examine $opt_* variables... .Ve .PP or .PP .Vb 6 \& use Getopt::Mixed "nextOption"; \& Getopt::Mixed::init(...option\-descriptions...); \& while (($option, $value) = nextOption()) { \& ...process option... \& } \& Getopt::Mixed::cleanup(); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\fBThis module is obsolete.\fR .PP This package was my response to the standard modules Getopt::Std and Getopt::Long. Std doesn't support long options, and Long didn't support short options. I wanted both, since long options are easier to remember and short options are faster to type. .PP However, years ago Getopt::Long was changed to support short options as well, and it has the huge advantage of being part of the standard Perl distribution. So, Getopt::Mixed is now effectively obsolete. I don't intend to make any more changes, but I'm leaving it available for people who have code that already uses it. For new modules, I recommend using Getopt::Long like this: .PP .Vb 3 \& use Getopt::Long 2.17; # Released with Perl 5.005 \& Getopt::Long::Configure(qw(bundling no_getopt_compat)); \& GetOptions(...option\-descriptions...); .Ve .PP This package was intended to be the \*(L"Getopt-to-end-all-Getop's\*(R". It combines (I hope) flexibility and simplicity. It supports both short options (introduced by \f(CW\*(C`\-\*(C'\fR) and long options (introduced by \f(CW\*(C`\-\-\*(C'\fR). Short options which do not take an argument can be grouped together. Short options which do take an argument must be the last option in their group, because everything following the option will be considered to be its argument. .PP There are two methods for using Getopt::Mixed: the simple method and the flexible method. Both methods use the same format for option descriptions. .SS "Option Descriptions" .IX Subsection "Option Descriptions" The option-description arguments required by \f(CW\*(C`init\*(C'\fR and \f(CW\*(C`getOptions\*(C'\fR are strings composed of individual option descriptions. Several option descriptions can appear in the same string if they are separated by whitespace. .PP Each description consists of the option name and an optional trailing argument specifier. Option names may consist of any characters but whitespace, \f(CW\*(C`=\*(C'\fR, \f(CW\*(C`:\*(C'\fR, and \f(CW\*(C`>\*(C'\fR. .PP Values for argument specifiers are: .PP .Vb 5 \& option does not take an argument \& =s :s option takes a mandatory (=) or optional (:) string argument \& =i :i option takes a mandatory (=) or optional (:) integer argument \& =f :f option takes a mandatory (=) or optional (:) real number argument \& >new option is a synonym for option \`new\*(Aq .Ve .PP The \f(CW\*(C`>\*(C'\fR specifier is not really an argument specifier. It defines an option as being a synonym for another option. For example, \&\*(L"a=i apples>a\*(R" would define \fB\-a\fR as an option that requires an integer argument and \fB\-\-apples\fR as a synonym for \fB\-a\fR. Only one level of synonyms is supported, and the root option must be listed first. For example, \*(L"apples>a a=i\*(R" and \*(L"a=i apples>a oranges>apples\*(R" are illegal; use \*(L"a=i apples>a oranges>a\*(R" if that's what you want. .PP For example, in the option description: \*(L"a b=i c:s apple baker>b charlie:s\*(R" \-a and \-\-apple do not take arguments \-b takes a mandatory integer argument \-\-baker is a synonym for \-b \-c and \-\-charlie take an optional string argument .PP If the first argument to \f(CW\*(C`init\*(C'\fR or \f(CW\*(C`getOptions\*(C'\fR is entirely non-alphanumeric characters with no whitespace, it represents the characters which can begin options. .SS "User Interface" .IX Subsection "User Interface" From the user's perspective, short options are introduced by a dash (\f(CW\*(C`\-\*(C'\fR) and long options are introduced by a double dash (\f(CW\*(C`\-\-\*(C'\fR). Short options may be combined (\*(L"\-a \-b\*(R" can be written \*(L"\-ab\*(R"), but an option that takes an argument must be the last one in its group, because anything following it is considered part of the argument. A double dash by itself marks the end of the options; all arguments following it are treated as normal arguments, not options. A single dash by itself is treated as a normal argument, \fInot\fR an option. .PP Long options may be abbreviated. An option \fB\-\-all\-the\-time\fR could be abbreviated \fB\-\-all\fR, \fB\-\-a\*(--tim\fR, or even \fB\-\-a\fR. Note that \fB\-\-time\fR would not work; the abbreviation must start at the beginning of the option name. If an abbreviation is ambiguous, an error message will be printed. .PP In the following examples, \fB\-i\fR and \fB\-\-int\fR take integer arguments, \&\fB\-f\fR and \fB\-\-float\fR take floating point arguments, and \fB\-s\fR and \&\fB\-\-string\fR take string arguments. All other options do not take an argument. .PP .Vb 2 \& \-i24 \-f24.5 \-sHello \& \-i=24 \-\-int=\-27 \-f=24.5 \-\-float=0.27 \-s=Hello \-\-string=Hello .Ve .PP If the argument is required, it can also be separated by whitespace: .PP .Vb 1 \& \-i 24 \-\-int \-27 \-f 24.5 \-\-float 0.27 \-s Hello \-\-string Hello .Ve .PP Note that if the option is followed by \f(CW\*(C`=\*(C'\fR, whatever follows the \f(CW\*(C`=\*(C'\fR \&\fIis\fR the argument, even if it's the null string. In the example .PP .Vb 1 \& \-i= 24 \-f= 24.5 \-s= Hello .Ve .PP \&\fB\-i\fR and \fB\-f\fR will cause an error, because the null string is not a number, but \fB\-s\fR is perfectly legal; its argument is the null string, not \*(L"Hello\*(R". .PP Remember that optional arguments \fIcannot\fR be separated from the option by whitespace. .SS "The Simple Method" .IX Subsection "The Simple Method" The simple method is .PP .Vb 2 \& use Getopt::Mixed; \& Getopt::Mixed::getOptions(...option\-descriptions...); .Ve .PP You then examine the \f(CW\*(C`$opt_*\*(C'\fR variables to find out what options were specified and the \f(CW@ARGV\fR array to see what arguments are left. .PP If \fB\-a\fR is an option that doesn't take an argument, then \f(CW$opt_a\fR will be set to 1 if the option is present, or left undefined if the option is not present. .PP If \fB\-b\fR is an option that takes an argument, then \f(CW$opt_b\fR will be set to the value of the argument if the option is present, or left undefined if the option is not present. If the argument is optional but not supplied, \f(CW$opt_b\fR will be set to the null string. .PP Note that even if you specify that an option \fIrequires\fR a string argument, you can still get the null string (if the user specifically enters it). If the option requires a numeric argument, you will never get the null string (because it isn't a number). .PP When converting the option name to a Perl identifier, any non-word characters in the name will be converted to underscores (\f(CW\*(C`_\*(C'\fR). .PP If the same option occurs more than once, only the last occurrence will be recorded. If that's not acceptable, you'll have to use the flexible method instead. .SS "The Flexible Method" .IX Subsection "The Flexible Method" The flexible method is .PP .Vb 6 \& use Getopt::Mixed "nextOption"; \& Getopt::Mixed::init(...option\-descriptions...); \& while (($option, $value, $pretty) = nextOption()) { \& ...process option... \& } \& Getopt::Mixed::cleanup(); .Ve .PP This lets you process arguments one at a time. You can then handle repeated options any way you want to. It also lets you see option names with non-alphanumeric characters without any translation. This is also the only method that lets you find out what order the options and other arguments were in. .PP First, you call Getopt::Mixed::init with the option descriptions. Then, you keep calling nextOption until it returns an empty list. Finally, you call Getopt::Mixed::cleanup when you're done. The remaining (non-option) arguments will be found in \f(CW@ARGV\fR. .PP Each call to nextOption returns a list of the next option, its value, and the option as the user typed it. The value will be undefined if the option does not take an argument. The option is stripped of its starter (e.g., you get \*(L"a\*(R" and \*(L"foo\*(R", not \*(L"\-a\*(R" or \*(L"\-\-foo\*(R"). If you want to print an error message, use the third element, which does include the option starter. .SH "OTHER FUNCTIONS" .IX Header "OTHER FUNCTIONS" Getopt::Mixed provides one other function you can use. \f(CW\*(C`abortMsg\*(C'\fR prints its arguments on \s-1STDERR,\s0 plus your program's name and a newline. It then exits with status 1. For example, if \fIfoo.pl\fR calls \f(CW\*(C`abortMsg\*(C'\fR like this: .PP .Vb 1 \& Getopt::Mixed::abortMsg("Error"); .Ve .PP The output will be: .PP .Vb 1 \& foo.pl: Error .Ve .SH "CUSTOMIZATION" .IX Header "CUSTOMIZATION" There are several customization variables you can set. All of these variables should be set \fIafter\fR calling Getopt::Mixed::init and \&\fIbefore\fR calling nextOption. .PP If you set any of these variables, you \fImust\fR check the version number first. The easiest way to do this is like this: .PP .Vb 1 \& use Getopt::Mixed 1.006; .Ve .PP If you are using the simple method, and you want to set these variables, you'll need to call init before calling getOptions, like this: .PP .Vb 4 \& use Getopt::Mixed 1.006; \& Getopt::Mixed::init(...option\-descriptions...); \& ...set configuration variables... \& Getopt::Mixed::getOptions(); # IMPORTANT: no parameters .Ve .ie n .IP "$order" 4 .el .IP "\f(CW$order\fR" 4 .IX Item "$order" \&\f(CW$order\fR can be set to \f(CW$REQUIRE_ORDER\fR, \f(CW$PERMUTE\fR, or \f(CW$RETURN_IN_ORDER\fR. The default is \f(CW$REQUIRE_ORDER\fR if the environment variable \&\s-1POSIXLY_CORRECT\s0 has been set, \f(CW$PERMUTE\fR otherwise. .Sp \&\f(CW$REQUIRE_ORDER\fR means that no options can follow the first argument which isn't an option. .Sp \&\f(CW$PERMUTE\fR means that all options are treated as if they preceded all other arguments. .Sp \&\f(CW$RETURN_IN_ORDER\fR means that all arguments maintain their ordering. When nextOption is called, and the next argument is not an option, it returns the null string as the option and the argument as the value. nextOption never returns the null list until all the arguments have been processed. .ie n .IP "$ignoreCase" 4 .el .IP "\f(CW$ignoreCase\fR" 4 .IX Item "$ignoreCase" Ignore case when matching options. Default is 1 unless the option descriptions contain an upper-case letter. .ie n .IP "$optionStart" 4 .el .IP "\f(CW$optionStart\fR" 4 .IX Item "$optionStart" A string of characters that can start options. Default is \*(L"\-\*(R". .ie n .IP "$badOption" 4 .el .IP "\f(CW$badOption\fR" 4 .IX Item "$badOption" A reference to a function that is called when an unrecognized option is encountered. The function receives three arguments. \f(CW$_[0]\fR is the position in \f(CW@ARGV\fR where the option came from. \f(CW$_[1]\fR is the option as the user typed it (including the option start character). \f(CW$_[2]\fR is either undef or a string describing the reason the option was not recognized (Currently, the only possible value is 'ambiguous', for a long option with several possible matches). The option has already been removed from \f(CW@ARGV\fR. To put it back, you can say: .Sp .Vb 1 \& splice(@ARGV,$_[0],0,$_[1]); .Ve .Sp The function can do anything you want to \f(CW@ARGV\fR. It should return whatever you want nextOption to return. .Sp The default is a function that prints an error message and exits the program. .ie n .IP "$checkArg" 4 .el .IP "\f(CW$checkArg\fR" 4 .IX Item "$checkArg" A reference to a function that is called to make sure the argument type is correct. The function receives four arguments. \f(CW$_[0]\fR is the position in \f(CW@ARGV\fR where the option came from. \f(CW$_[1]\fR is the text following the option, or undefined if there was no text following the option. \f(CW$_[2]\fR is the name of the option as the user typed it (including the option start character), suitable for error messages. \&\f(CW$_[3]\fR is the argument type specifier. .Sp The function can do anything you want to \f(CW@ARGV\fR. It should return the value for this option. .Sp The default is a function that prints an error message and exits the program if the argument is not the right type for the option. You can also adjust the behavior of the default function by changing \&\f(CW$intRegexp\fR or \f(CW$floatRegexp\fR. .ie n .IP "$intRegexp" 4 .el .IP "\f(CW$intRegexp\fR" 4 .IX Item "$intRegexp" A regular expression that matches an integer. Default is \&'^[\-+]?\ed+$', which matches a string of digits preceded by an optional sign. Unlike the other configuration variables, this cannot be changed after nextOption is called, because the pattern is compiled only once. .ie n .IP "$floatRegexp" 4 .el .IP "\f(CW$floatRegexp\fR" 4 .IX Item "$floatRegexp" A regular expression that matches a floating point number. Default is \&'^[\-+]?(\ed*\e.?\ed+|\ed+\e.)$', which matches the following formats: \&\*(L"123\*(R", \*(L"123.\*(R", \*(L"123.45\*(R", and \*(L".123\*(R" (plus an optional sign). It does not match exponential notation. Unlike the other configuration variables, this cannot be changed after nextOption is called, because the pattern is compiled only once. .ie n .IP "$typeChars" 4 .el .IP "\f(CW$typeChars\fR" 4 .IX Item "$typeChars" A string of the characters which are legal argument types. The default is 'sif', for String, Integer, and Floating point arguments. The string should consist only of letters. Upper case letters are discouraged, since this will hamper the case-folding of options. If you change this, you should set \f(CW$checkType\fR to a function that will check arguments of your new type. Unlike the other configuration variables, this must be set \fIbefore\fR calling \fIinit()\fR, and cannot be changed afterwards. .ie n .IP "$checkType" 4 .el .IP "\f(CW$checkType\fR" 4 .IX Item "$checkType" If you add new types to \f(CW$typeChars\fR, you should set this to a function which will check arguments of the new types. .SH "SEE ALSO" .IX Header "SEE ALSO" Getopt::Long .SH "CONFIGURATION AND ENVIRONMENT" .IX Header "CONFIGURATION AND ENVIRONMENT" Getopt::Mixed requires no configuration files or environment variables. .SH "INCOMPATIBILITIES" .IX Header "INCOMPATIBILITIES" None reported. .SH "BUGS AND LIMITATIONS" .IX Header "BUGS AND LIMITATIONS" .IP "\(bu" 4 This document should be expanded. .IP "\(bu" 4 A long option must be at least two characters long. Sorry. .IP "\(bu" 4 The \f(CW\*(C`!\*(C'\fR argument specifier of Getopt::Long is not supported, but you could have options \fB\-\-foo\fR and \fB\-\-nofoo\fR and then do something like: .Sp .Vb 1 \& $opt_foo = 0 if $opt_nofoo; .Ve .IP "\(bu" 4 The \f(CW\*(C`@\*(C'\fR argument specifier of Getopt::Long is not supported. If you want your values pushed into an array, you'll have to use nextOption and do it yourself. .SH "AUTHOR" .IX Header "AUTHOR" Christopher J. Madsen \f(CW\*(C`\*(C'\fR .PP Please report any bugs or feature requests to \f(CW\*(C`\*(C'\fR or through the web interface at . .PP You can follow or contribute to Getopt::Mixed's development at . .PP Thanks are also due to Andreas Koenig for helping Getopt::Mixed conform to the standards for Perl modules and for answering a bunch of questions. Any remaining deficiencies are my fault. .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 1995 by Christopher J. Madsen. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. .SH "DISCLAIMER OF WARRANTY" .IX Header "DISCLAIMER OF WARRANTY" \&\s-1BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE \*(L"AS IS\*(R" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.\s0 .PP \&\s-1IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE\s0 (\s-1INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE\s0), \s-1EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.\s0