Over the course of the next few pages, I will introduce you to one of the more interesting modules in the Perl pantheon, the Getopt::Long.pm module. This module provides a simple API to parse options passed to your Perl scripts at the command line and convert them into Perl scalars or arrays.
In addition to setting Booleans, Getopt::Long.pm also supports processing string and numeric command-line arguments entered by the user. To illustrate how this works, consider the following simple example:
# print value if ($age) { print "Input age is $age years"; }
Here's the output:
$ ./script.pl --age=89 Input age is 89 years
Here, the "i" data type specifier tells Getopy::Long.pm to expect an integer value after the option name. You can also use "s" for strings, as in the following example: