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.
Most of the magic here lies in the call to the GetOptions() function. This function accepts a series of option-variable pairs, demarcated using standard hash notation and separated with commas. When GetOptions() is called, it reads the program command line, looks for matching arguments, and if found, sets the corresponding option variable to true. Thus when you call the Perl script above with the "--debug" option, GetOptions() recognizes it and automatically sets the $debug variable to true.
You can set more than one option variable at a time as well. Consider the following example and its output, which demonstrates: