DEV.MD / Developer Network

Email to friend
* Your name:
* Your email:
* Friend's email:
Comment:


Processing Command Line Options with PERL

CPAN Documentation

--- CODE
#!/usr/bin/perl
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";
---END CODE

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




RSS