Skip to content

Instantly share code, notes, and snippets.

@avances123
Created November 30, 2010 15:55
Show Gist options
  • Save avances123/721865 to your computer and use it in GitHub Desktop.
Save avances123/721865 to your computer and use it in GitHub Desktop.
This is a simplified example for cut and paste use for command line parsing arguments with the use of an options hash
#!/usr/bin/perl -w
##Simplified example of using Getopt:Long moudule with an Options hash
use Getopt::Long;
use strict;
my %Opt=();
(GetOptions( \%Opt,
"h|help",
"s|string=s",
"l|list=s@",
"i|int=i",
"f|float=f",
"o|octal=o",
)) || die "ERROR: Illegal arguments or parameters: @ARGV\n" unless ($#ARGV < 0);
## Or as OO
#
#my $parser = new Getopt::Long::Parser;
#$parser->configure("no_ignore_case");
#if ($parser->getoptions(\%Opt,
# "h|help",
# "s|string=s",
# "l|list=s@",
# "i|int=i",
# "f|float=f",
# "o|octal=o",
#)) {};
#
## Just print out the options for each collected to see what there is:
foreach my $key (keys %Opt) {
print "$key is $Opt{$key}\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment