Created
November 30, 2010 15:55
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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