blob: 9f383699ebb2ae7210e2a2e535f55968502ffdc9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
$OpenBSD: OpenBSD::Getopt.pod,v 1.4 2010/06/30 10:51:04 espie Exp $
=head1 NAME
OpenBSD::Getopt - Process single-characters switches
=head1 SYNOPSIS
use OpenBSD::Getopt;
our($opt_o, $opt_i, $opt_f, $opt_v);
getopts('oifv:',
{ 'v' => sub {
++$opt_v;}
}
=head1 DESCRIPTION
This is similar to L<getopt(3)>. One call to C<getopts($optstring)> parses
all the options using the C<$optstring> as a list of simple switches
(letter) and switches with arguments (letter followed by C<:>).
Option values are directly written into local variables of the form
C<$opt_S>, where C<S> is the switch name.
Contrary to L<getopt(3)>, C<$opt_S> is incremented each time the switch is
seen, to allow for stuff like C<-vv>.
An optional hash can be used as a second argument, with switches as keys
and subs as values. When a switch is met, the sub C<$foo> is called as
C<$foo> for a simple switch and as C<$foo(option_value)> for a switch
with argument.
|