perl getopts example

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


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


Popular posts from this blog

Vim vi how to reload a file your editing