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