Debian Codegraph @

upstream/mageia-cauldron/man3pm/Getopt::Std.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\"
56 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "Getopt::Std 3pm"
61 .TH Getopt::Std 3pm 2023-12-22 "perl v5.42.0" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 Getopt::Std \- Process single\-character switches with switch clustering
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 1
71 \& use Getopt::Std;
72 \&
73 \& getopts(\*(Aqoif:\*(Aq); # \-o & \-i are boolean flags, \-f takes an argument
74 \& # Sets $opt_* global variables as a side effect
75 \& getopts(\*(Aqoif:\*(Aq, \emy %opts); # Options as above, values in %opts
76 \& getopt(\*(AqoDI\*(Aq); # \-o, \-D & \-I take arguments
77 \& # Sets $opt_* global variables as a side effect
78 \& getopt(\*(AqoDI\*(Aq, \emy %opts); # \-o, \-D & \-I take arg, values in %opts
79 .Ve
80 .SH DESCRIPTION
81 .IX Header "DESCRIPTION"
82 The \f(CWgetopts()\fR function processes single\-character switches with switch
83 clustering. Pass one argument which is a string containing all switches to be
84 recognized. For each switch found, if an argument is expected and provided,
85 \&\f(CWgetopts()\fR sets \f(CW$opt_x\fR (where \f(CW\*(C`x\*(C'\fR is the switch name) to the value of
86 the argument. If an argument is expected but none is provided, \f(CW$opt_x\fR is
87 set to an undefined value. If a switch does not take an argument, \f(CW$opt_x\fR
88 is set to \f(CW1\fR.
89 .PP
90 Switches which take an argument don\*(Aqt care whether there is a space between
91 the switch and the argument. If unspecified switches are found on the
92 command\-line, the user will be warned that an unknown option was given.
93 .PP
94 The \f(CWgetopts()\fR function returns true unless an invalid option was found.
95 .PP
96 The \f(CWgetopt()\fR function is similar, but its argument is a string containing
97 all switches that take an argument. If no argument is provided for a switch,
98 say, \f(CW\*(C`y\*(C'\fR, the corresponding \f(CW$opt_y\fR will be set to an undefined value.
99 Unspecified switches are silently accepted. Use of \f(CWgetopt()\fR is \fBnot
100 recommended\fR.
101 .PP
102 Note that, if your code is running under the recommended \f(CW\*(C`use strict
103 vars\*(C'\fR pragma, you will need to declare these package variables
104 with \f(CW\*(C`our\*(C'\fR:
105 .PP
106 .Vb 1
107 \& our($opt_x, $opt_y);
108 .Ve
109 .PP
110 For those of you who don\*(Aqt like additional global variables being created,
111 \&\f(CWgetopt()\fR and \f(CWgetopts()\fR will also accept a hash reference as an optional
112 second argument. Hash keys will be \f(CW\*(C`x\*(C'\fR (where \f(CW\*(C`x\*(C'\fR is the switch name) with
113 key values the value of the argument or \f(CW1\fR if no argument is specified.
114 .PP
115 To allow programs to process arguments that look like switches, but aren\*(Aqt,
116 both functions will stop processing switches when they see the argument
117 \&\f(CW\*(C`\-\-\*(C'\fR. The \f(CW\*(C`\-\-\*(C'\fR will be removed from \f(CW@ARGV\fR.
118 .ie n .SH """\-\-help"" and ""\-\-version"""
119 .el .SH "\f(CW\-\-help\fP and \f(CW\-\-version\fP"
120 .IX Header "--help and --version"
121 If \f(CW\*(C`\-\*(C'\fR is not a recognized switch letter, \f(CWgetopts()\fR supports arguments
122 \&\f(CW\*(C`\-\-help\*(C'\fR and \f(CW\*(C`\-\-version\*(C'\fR. If \f(CWmain::HELP_MESSAGE()\fR and/or
123 \&\f(CWmain::VERSION_MESSAGE()\fR are defined, they are called; the arguments are
124 the output file handle, the name of option\-processing package, its version,
125 and the switches string. If the subroutines are not defined, an attempt is
126 made to generate intelligent messages; for best results, define \f(CW$main::VERSION\fR.
127 .PP
128 If embedded documentation (in pod format, see perlpod) is detected
129 in the script, \f(CW\*(C`\-\-help\*(C'\fR will also show how to access the documentation.
130 .PP
131 Note that due to excessive paranoia, if \f(CW$Getopt::Std::STANDARD_HELP_VERSION\fR
132 isn\*(Aqt true (the default is false), then the messages are printed on \f(CW\*(C`STDERR\*(C'\fR,
133 and the processing continues after the messages are printed. This being
134 the opposite of the standard\-conforming behaviour, it is strongly recommended
135 to set \f(CW$Getopt::Std::STANDARD_HELP_VERSION\fR to true.
136 .PP
137 One can change the output file handle of the messages by setting
138 \&\f(CW$Getopt::Std::OUTPUT_HELP_VERSION\fR. One can print the messages of \f(CW\*(C`\-\-help\*(C'\fR
139 (without the \f(CW\*(C`Usage:\*(C'\fR line) and \f(CW\*(C`\-\-version\*(C'\fR by calling functions \f(CWhelp_mess()\fR
140 and \f(CWversion_mess()\fR with the switches string as an argument.