in reply to Re: problem with Getopt::Long
in thread problem with Getopt::Long
Getopt eats up the values in @ARGV so it is alway empty
Just to be nitpicky -- not quite. Getopt eats the options in @ARGV. Anything else will remain. Consider the following:
and note the output:#!/usr/bin/perl use Getopt::Long; GetOptions( "i" => \$options{i}, "o=s" => \$options{o}, "p=s" => \$options{p}, "h" => \$options{h} ); foreach $arg (@ARGV) { print "$arg is still in ARGV\n"; } foreach $opt (keys %options) { print "$opt is $options{$opt}\n" if $options{$opt}; }
nkuvu$ perl try.pl --i h --o=foo h is still in ARGV o is foo i is 1
I have used this to check some command line inputs. Specifically, for most of my scripts anything specified on the command line should be an option. Anything after that is an error. So I'd use it sort of like:
GetOptions( #whatever ); die "Gah! (with appropriate error message here)\n" if (@ARGV);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: problem with Getopt::Long
by Random_Walk (Prior) on Aug 20, 2004 at 10:15 UTC | |
by Nkuvu (Priest) on Aug 20, 2004 at 10:23 UTC | |
by Aristotle (Chancellor) on Aug 20, 2004 at 11:22 UTC | |
by Nkuvu (Priest) on Aug 20, 2004 at 13:40 UTC | |
by Random_Walk (Prior) on Aug 20, 2004 at 10:30 UTC |