Processing Command Line Options with PERL - Down To Work (Page 3 of 9 )
Now, with the hard sell out of the way, let's get down to the nitty-gritty of how Getopt::Long.pm works. Consider the following simple example:
#!/usr/bin/perl
# import module
use Getopt::Long;
# set default value for option
$debug = 0;
# get value of debug flag
$result = GetOptions ("debug" => $debug);
# print value
print "Debug flag is $debug";
Now, try running this code as is:
$ ./script.pl
Debug flag is 0
And then try running it after adding a "--debug" command-line option:
$ ./script.pl --debug
Debug flag is 1
As you can see, the Perl code now recognizes the "--debug" flag on the command line, and sets a Boolean variable to true within the script.
Next: GetOptions() Function >>
More Perl Articles
More By icarus, (c) Melonfire