Return to Snippet

Revision: 10985
at June 9, 2009 17:44 by kfaulk1


Updated Code
#!/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";
}

Revision: 10984
at January 20, 2009 17:13 by kfaulk1


Initial Code
#!/usr/bin/perl -w

##Simplified example of using Getopt:Long moudule with an Options hash

use Getopt::Long;

(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";
}

Initial URL


Initial Description
This is a simplified example for cut and paste use for command line parsing arguments with the use of an options hash

Initial Title
Using Getopt::Long for Command Line Parsing in Perl

Initial Tags
command, line

Initial Language
Perl