Install Perl 5.8.8
[msysgit.git] / mingw / html / lib / Getopt / Std.html
blob1e92ca9b6dd1a0dac93e5fd163a4cd33a5683515
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>getopts - Process single-character switches with switch clustering</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:" />
8 </head>
10 <body style="background-color: white">
11 <table border="0" width="100%" cellspacing="0" cellpadding="3">
12 <tr><td class="block" style="background-color: #cccccc" valign="middle">
13 <big><strong><span class="block">&nbsp;getopts - Process single-character switches with switch clustering</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
22 <li><a href="#name">NAME</a></li>
23 <li><a href="#synopsis">SYNOPSIS</a></li>
24 <li><a href="#description">DESCRIPTION</a></li>
25 <li><a href="#help_and_version"><code>-help</code> and <code>-version</code></a></li>
26 </ul>
27 <!-- INDEX END -->
29 <hr />
30 <p>
31 </p>
32 <h1><a name="name">NAME</a></h1>
33 <p>getopt, getopts - Process single-character switches with switch clustering</p>
34 <p>
35 </p>
36 <hr />
37 <h1><a name="synopsis">SYNOPSIS</a></h1>
38 <pre>
39 use Getopt::Std;</pre>
40 <pre>
41 getopt('oDI'); # -o, -D &amp; -I take arg. Sets $opt_* as a side effect.
42 getopt('oDI', \%opts); # -o, -D &amp; -I take arg. Values in %opts
43 getopts('oif:'); # -o &amp; -i are boolean flags, -f takes an argument
44 # Sets $opt_* as a side effect.
45 getopts('oif:', \%opts); # options as above. Values in %opts</pre>
46 <p>
47 </p>
48 <hr />
49 <h1><a name="description">DESCRIPTION</a></h1>
50 <p>The <code>getopt()</code> function processes single-character switches with switch
51 clustering. Pass one argument which is a string containing all switches
52 that take an argument. For each switch found, sets $opt_x (where x is the
53 switch name) to the value of the argument if an argument is expected,
54 or 1 otherwise. Switches which take an argument don't care whether
55 there is a space between the switch and the argument.</p>
56 <p>The <code>getopts()</code> function is similar, but you should pass to it the list of all
57 switches to be recognized. If unspecified switches are found on the
58 command-line, the user will be warned that an unknown option was given.</p>
59 <p>Note that, if your code is running under the recommended <code>use strict
60 'vars'</code> pragma, you will need to declare these package variables
61 with ``our'':</p>
62 <pre>
63 our($opt_x, $opt_y);</pre>
64 <p>For those of you who don't like additional global variables being created, <code>getopt()</code>
65 and <code>getopts()</code> will also accept a hash reference as an optional second argument.
66 Hash keys will be x (where x is the switch name) with key values the value of
67 the argument or 1 if no argument is specified.</p>
68 <p>To allow programs to process arguments that look like switches, but aren't,
69 both functions will stop processing switches when they see the argument
70 <code>--</code>. The <code>--</code> will be removed from @ARGV.</p>
71 <p>
72 </p>
73 <hr />
74 <h1><a name="help_and_version"><code>--help</code> and <code>--version</code></a></h1>
75 <p>If <code>-</code> is not a recognized switch letter, <code>getopts()</code> supports arguments
76 <code>--help</code> and <code>--version</code>. If <code>main::HELP_MESSAGE()</code> and/or
77 <code>main::VERSION_MESSAGE()</code> are defined, they are called; the arguments are
78 the output file handle, the name of option-processing package, its version,
79 and the switches string. If the subroutines are not defined, an attempt is
80 made to generate intelligent messages; for best results, define $main::VERSION.</p>
81 <p>If embedded documentation (in pod format, see <a href="file://C|\msysgit\mingw\html/pod/perlpod.html">the perlpod manpage</a>) is detected
82 in the script, <code>--help</code> will also show how to access the documentation.</p>
83 <p>Note that due to excessive paranoia, if $Getopt::Std::STANDARD_HELP_VERSION
84 isn't true (the default is false), then the messages are printed on STDERR,
85 and the processing continues after the messages are printed. This being
86 the opposite of the standard-conforming behaviour, it is strongly recommended
87 to set $Getopt::Std::STANDARD_HELP_VERSION to true.</p>
88 <p>One can change the output file handle of the messages by setting
89 $Getopt::Std::OUTPUT_HELP_VERSION. One can print the messages of <code>--help</code>
90 (without the <code>Usage:</code> line) and <code>--version</code> by calling functions <code>help_mess()</code>
91 and <code>version_mess()</code> with the switches string as an argument.</p>
92 <table border="0" width="100%" cellspacing="0" cellpadding="3">
93 <tr><td class="block" style="background-color: #cccccc" valign="middle">
94 <big><strong><span class="block">&nbsp;getopts - Process single-character switches with switch clustering</span></strong></big>
95 </td></tr>
96 </table>
98 </body>
100 </html>