Getopt::Long
If your program says:
use Getopt::Long;
GetOptions("verbose" => \$verbose,
"debug" => \$debug,
"output=s" => \$output);it can be called from the command line like this:
%prog --verbose more args here%prog --debug more args here%prog -v -d more args here%prog --output=somefile more args here%prog -o somefile more args here
The Getopt::Long module provides a
GetOptions function to process command-line
switches with long names. It includes support for things like
abbreviating switches, typed arguments like Boolean or string or
integer or float, array variables for repeating options, user-defined
validation routines, POSIX-conforming versus FSF-style processing,
case-insensitive options, and traditional bundling of short
options—just to name a few out of its vast cornucopia of features. If
this module is overkill, consider the more traditional
Getopt::Std module described next. If this module
is underkill, check out the CPAN module
Getopt::Declare, which provides a more declarative
syntax for option specification.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access