perl getopts example

http://perldoc.perl.org/Getopt/Long.html

I love perl's getopt example, it's very easy to use and to the point.

Here is the standard example from the documentation

use Getopt::Long;
my $data = "file.dat";
my $length = 24;
my $verbose;
$result = GetOptions ("length=i" => \$length, # numeric
"file=s" => \$data, # string
"verbose" => \$verbose); # flag


All you need to do now to check if your variable is is set and use it

Example:

if(! defined $data) {
die "Throwing error because required field isn't set.";
}

Comments

Popular posts from this blog

Vim vi how to reload a file your editing