OpenBSD::Getopt(3p)

OpenBSD::Getopt3p

Process single-characters switches

Usage

   use OpenBSD::Getopt;
   my $h = { 'v' => 
            sub() {
                ++$opt_v;
            };
   };
   getopts('oifv:', $h);

Overview

This is similar to getopt(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 getopt(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.

Releases

32 releases since OpenBSD 5.0; the text changed 20 times.

  1. 5.0–5.3
  2. 5.4–5.5
  3. 5.6
  4. 5.7
  5. 5.8–5.9
  6. 6.0
  7. 6.1
  8. 6.2
  9. 6.3–6.4
  10. 6.5
  11. 6.6
  12. 6.7
  13. 6.8
  14. 6.9–7.2
  15. 7.3
  16. 7.4
  17. 7.5
  18. 7.6
  19. 7.7–7.8
  20. 7.9
  21. 8.0

From man 8.0-current-20261101 in OpenBSD 8.0-current (2026-11-01). Parsed by carta from the page's man source.