Debian Codegraph @

upstream/debian-unstable/man3/Getopt::Std.3perl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (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 .\"
57 .IX Title "Getopt::Std 3perl"
58 .TH Getopt::Std 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide"
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 Getopt::Std \- Process single\-character switches with switch clustering
65 .SH SYNOPSIS
66 .IX Header "SYNOPSIS"
67 .Vb 1
68 \& use Getopt::Std;
69 \&
70 \& getopts(\*(Aqoif:\*(Aq); # \-o & \-i are boolean flags, \-f takes an argument
71 \& # Sets $opt_* global variables as a side effect
72 \& getopts(\*(Aqoif:\*(Aq, \emy %opts); # Options as above, values in %opts
73 \& getopt(\*(AqoDI\*(Aq); # \-o, \-D & \-I take arguments
74 \& # Sets $opt_* global variables as a side effect
75 \& getopt(\*(AqoDI\*(Aq, \emy %opts); # \-o, \-D & \-I take arg, values in %opts
76 .Ve
77 .SH DESCRIPTION
78 .IX Header "DESCRIPTION"
79 The \f(CWgetopts()\fR function processes single-character switches with switch
80 clustering. Pass one argument which is a string containing all switches to be
81 recognized. For each switch found, if an argument is expected and provided,
82 \&\f(CWgetopts()\fR sets \f(CW$opt_x\fR (where \f(CW\*(C`x\*(C'\fR is the switch name) to the value of
83 the argument. If an argument is expected but none is provided, \f(CW$opt_x\fR is
84 set to an undefined value. If a switch does not take an argument, \f(CW$opt_x\fR
85 is set to \f(CW1\fR.
86 .PP
87 Switches which take an argument don't care whether there is a space between
88 the switch and the argument. If unspecified switches are found on the
89 command-line, the user will be warned that an unknown option was given.
90 .PP
91 The \f(CWgetopts()\fR function returns true unless an invalid option was found.
92 .PP
93 The \f(CWgetopt()\fR function is similar, but its argument is a string containing
94 all switches that take an argument. If no argument is provided for a switch,
95 say, \f(CW\*(C`y\*(C'\fR, the corresponding \f(CW$opt_y\fR will be set to an undefined value.
96 Unspecified switches are silently accepted. Use of \f(CWgetopt()\fR is \fBnot
97 recommended\fR.
98 .PP
99 Note that, if your code is running under the recommended \f(CW\*(C`use strict
100 vars\*(C'\fR pragma, you will need to declare these package variables
101 with \f(CW\*(C`our\*(C'\fR:
102 .PP
103 .Vb 1
104 \& our($opt_x, $opt_y);
105 .Ve
106 .PP
107 For those of you who don't like additional global variables being created,
108 \&\f(CWgetopt()\fR and \f(CWgetopts()\fR will also accept a hash reference as an optional
109 second argument. Hash keys will be \f(CW\*(C`x\*(C'\fR (where \f(CW\*(C`x\*(C'\fR is the switch name) with
110 key values the value of the argument or \f(CW1\fR if no argument is specified.
111 .PP
112 To allow programs to process arguments that look like switches, but aren't,
113 both functions will stop processing switches when they see the argument
114 \&\f(CW\*(C`\-\-\*(C'\fR. The \f(CW\*(C`\-\-\*(C'\fR will be removed from \f(CW@ARGV\fR.
115 .ie n .SH """\-\-help"" and ""\-\-version"""
116 .el .SH "\f(CW\-\-help\fP and \f(CW\-\-version\fP"
117 .IX Header "--help and --version"
118 If \f(CW\*(C`\-\*(C'\fR is not a recognized switch letter, \f(CWgetopts()\fR supports arguments
119 \&\f(CW\*(C`\-\-help\*(C'\fR and \f(CW\*(C`\-\-version\*(C'\fR. If \f(CWmain::HELP_MESSAGE()\fR and/or
120 \&\f(CWmain::VERSION_MESSAGE()\fR are defined, they are called; the arguments are
121 the output file handle, the name of option-processing package, its version,
122 and the switches string. If the subroutines are not defined, an attempt is
123 made to generate intelligent messages; for best results, define \f(CW$main::VERSION\fR.
124 .PP
125 If embedded documentation (in pod format, see perlpod) is detected
126 in the script, \f(CW\*(C`\-\-help\*(C'\fR will also show how to access the documentation.
127 .PP
128 Note that due to excessive paranoia, if \f(CW$Getopt::Std::STANDARD_HELP_VERSION\fR
129 isn't true (the default is false), then the messages are printed on \f(CW\*(C`STDERR\*(C'\fR,
130 and the processing continues after the messages are printed. This being
131 the opposite of the standard-conforming behaviour, it is strongly recommended
132 to set \f(CW$Getopt::Std::STANDARD_HELP_VERSION\fR to true.
133 .PP
134 One can change the output file handle of the messages by setting
135 \&\f(CW$Getopt::Std::OUTPUT_HELP_VERSION\fR. One can print the messages of \f(CW\*(C`\-\-help\*(C'\fR
136 (without the \f(CW\*(C`Usage:\*(C'\fR line) and \f(CW\*(C`\-\-version\*(C'\fR by calling functions \f(CWhelp_mess()\fR
137 and \f(CWversion_mess()\fR with the switches string as an argument.