OpenBSD::Getopt(3p) Perl Programmers Reference Guide OpenBSD::Getopt(3p) #
OpenBSD::Getopt(3p) Perl Programmers Reference Guide OpenBSD::Getopt(3p)
NNAAMMEE #
OpenBSD::Getopt - Process single-characters switches
SSYYNNOOPPSSIISS #
use OpenBSD::Getopt;
my $h = { 'v' =>
sub() {
++$opt_v;
};
};
getopts('oifv:', $h);
DDEESSCCRRIIPPTTIIOONN #
This is similar to ggeettoopptt(3). One call to "getopts($optstring, $h)"
parses all the options using the $optstring as a list of simple switches
(letter) and switches with arguments (letter followed by ":").
Option values are written into the hash $h. Contrary to ggeettoopptt(3),
"$h->{v}" is incremented each time the switch is seen, to allow for stuff
like "-vv".
Alternately, a code ref can be put into the hash for a given switch.
When a switch is seen, the sub $foo is called as "&$foo()" for a simple
switch and as "&$foo(option_value)" for a switch with argument.
perl v5.36.3 2023-05-21 OpenBSD::Getopt(3p)