56
56
<li><a href="http://search.cpan.org">CPAN</a></li>
57
<li><a href="http://www.perl.org">Perl.org</a></li>
57
58
<li><a href="http://www.perl.com">Perl.com</a></li>
58
<li><a href="http://www.perl.org">Perl.org</a></li>
59
<li><a href="http://perlbuzz.com">Perl Buzz</a></li>
60
<li><a href="http://www.perlfoundation.org/perl5/index.cgi">Perl 5 Wiki</a></li>
61
<li><a href="http://jobs.perl.org">Perl Jobs</a></li>
59
62
<li><a href="http://www.pm.org">Perl Mongers</a></li>
60
63
<li><a href="http://www.perlmonks.org">Perl Monks</a></li>
61
64
<li><a href="http://planet.perl.org">Planet Perl</a></li>
66
69
<li>Site maintained by<br><a href="http://perl.jonallen.info">Jon Allen</a>
67
70
(<a href="http://perl.jonallen.info">JJ</a>)</li>
68
<li class="spaced">Last updated on<br>23 April 2006</li>
71
<li class="spaced">Last updated on<br>23 December 2007</li>
69
72
<li class="spaced">See the <a href="http://perl.jonallen.info/projects/perldoc">project page</a> for
76
79
<div id="centerContent">
77
80
<div id="contentHeader">
78
81
<div id="contentHeaderLeft"><a href="#" onClick="showLeft()">Show navigation</a></div>
79
<div id="contentHeaderCentre">-- Perl 5.8.8 documentation --</div>
82
<div id="contentHeaderCentre">-- Perl 5.10.0 documentation --</div>
80
83
<div id="contentHeaderRight"><a href="#" onClick="showRight()">Show toolbar</a></div>
82
85
<div id="breadCrumbs"><a href="../index.html">Home</a> > <a href="../index-modules-A.html">Core modules</a> > <a href="../index-modules-G.html">G</a> > Getopt::Std</div>
83
86
<script language="JavaScript">fromSearch();</script>
84
<div id="contentBody"><div class="title_container"><div class="page_title">Getopt::Std</div></div><ul><li><a href="#NAME">NAME</a><li><a href="#SYNOPSIS">SYNOPSIS</a><li><a href="#DESCRIPTION">DESCRIPTION</a><li><a href="#'--help'-and-'--version'"><code class="inline">--help</code>
85
and <code class="inline">--version</code>
87
<div id="contentBody"><div class="title_container"><div class="page_title">Getopt::Std</div></div><ul><li><a href="#NAME">NAME</a><li><a href="#SYNOPSIS">SYNOPSIS</a><li><a href="#DESCRIPTION">DESCRIPTION</a><li><a href="#'--help'-and-'--version'"><code class="inline">--<span class="w">help</span></code>
88
and <code class="inline">--<span class="w">version</span></code>
86
89
</a></ul><a name="NAME"></a><h1>NAME</h1>
87
90
<p>getopt, getopts - Process single-character switches with switch clustering</p>
88
91
<a name="SYNOPSIS"></a><h1>SYNOPSIS</h1>
89
<pre class="verbatim"> <a class="l_k" href="../functions/use.html">use</a> <a class="l_w" href="../Getopt/Std.html">Getopt::Std</a><span class="sc">;</span></pre>
92
<pre class="verbatim"> <a class="l_k" href="../functions/use.html">use</a> <span class="w">Getopt::Std</span><span class="sc">;</span></pre>
90
93
<pre class="verbatim"> <span class="i">getopt</span><span class="s">(</span><span class="q">'oDI'</span><span class="s">)</span><span class="sc">;</span> <span class="c"># -o, -D & -I take arg. Sets $opt_* as a side effect.</span>
91
94
<span class="i">getopt</span><span class="s">(</span><span class="q">'oDI'</span><span class="cm">,</span> \<span class="i">%opts</span><span class="s">)</span><span class="sc">;</span> <span class="c"># -o, -D & -I take arg. Values in %opts</span>
92
95
<span class="i">getopts</span><span class="s">(</span><span class="q">'oif:'</span><span class="s">)</span><span class="sc">;</span> <span class="c"># -o & -i are boolean flags, -f takes an argument</span>
101
104
there is a space between the switch and the argument.</p>
102
105
<p>The getopts() function is similar, but you should pass to it the list of all
103
106
switches to be recognized. If unspecified switches are found on the
104
command-line, the user will be warned that an unknown option was given.</p>
105
<p>Note that, if your code is running under the recommended <code class="inline"><a class="l_k" href="../functions/use.html">use</a> <a class="l_w" href="../strict.html">strict</a>
107
command-line, the user will be warned that an unknown option was given.
108
The getopts() function returns true unless an invalid option was found.</p>
109
<p>Note that, if your code is running under the recommended <code class="inline"><a class="l_k" href="../functions/use.html">use</a> <span class="w">strict</span>
106
110
<span class="q">'vars'</span></code>
107
111
pragma, you will need to declare these package variables
116
120
<code class="inline">--</code>
117
121
. The <code class="inline">--</code>
118
122
will be removed from @ARGV.</p>
119
<a name="'--help'-and-'--version'"></a><h1><code class="inline">--help</code>
120
and <code class="inline">--version</code>
123
<a name="'--help'-and-'--version'"></a><h1><code class="inline">--<span class="w">help</span></code>
124
and <code class="inline">--<span class="w">version</span></code>
122
126
<p>If <code class="inline">-</code>
123
127
is not a recognized switch letter, getopts() supports arguments
124
<code class="inline">--help</code>
125
and <code class="inline">--version</code>
128
<code class="inline">--<span class="w">help</span></code>
129
and <code class="inline">--<span class="w">version</span></code>
126
130
. If <code class="inline"><span class="i">main::HELP_MESSAGE</span><span class="s">(</span><span class="s">)</span></code>
128
132
<code class="inline"><span class="i">main::VERSION_MESSAGE</span><span class="s">(</span><span class="s">)</span></code>
131
135
and the switches string. If the subroutines are not defined, an attempt is
132
136
made to generate intelligent messages; for best results, define $main::VERSION.</p>
133
137
<p>If embedded documentation (in pod format, see <a href="../perlpod.html">perlpod</a>) is detected
134
in the script, <code class="inline">--help</code>
138
in the script, <code class="inline">--<span class="w">help</span></code>
135
139
will also show how to access the documentation.</p>
136
140
<p>Note that due to excessive paranoia, if $Getopt::Std::STANDARD_HELP_VERSION
137
141
isn't true (the default is false), then the messages are printed on STDERR,
139
143
the opposite of the standard-conforming behaviour, it is strongly recommended
140
144
to set $Getopt::Std::STANDARD_HELP_VERSION to true.</p>
141
145
<p>One can change the output file handle of the messages by setting
142
$Getopt::Std::OUTPUT_HELP_VERSION. One can print the messages of <code class="inline">--help</code>
146
$Getopt::Std::OUTPUT_HELP_VERSION. One can print the messages of <code class="inline">--<span class="w">help</span></code>
144
148
(without the <code class="inline"><span class="j">Usage:</span></code>
145
line) and <code class="inline">--version</code>
149
line) and <code class="inline">--<span class="w">version</span></code>
146
150
by calling functions help_mess()
147
151
and version_mess() with the switches string as an argument.</p>