On Thu, Jun 17, 2010 at 02:36, Unknown User <knowsuperunkn...@gmail.com> wrote: > I have the following code: > > GetOptions( > "n|name=s" => \$name, > "a|age=i" => \$age, > "s|sex=s" => \$sex, > ) || die "Bad options\n";; > > What i expected this code to do is to die if a bad option was given, > say -s without an arguement, as in ./myprog -n name -s -a 20 > However, it does not do that. > > What would be the correct method to die if one of the options is not complete?
GetOptions should print a warning and return a false value in that case. What version of Perl and Getopt::Long are you using? Try running the following code. If it does not die, then there is a problem outside of your code. #!/usr/bin/perl use strict; use warnings; use Getopt::Long; for my $args ([qw/-n a/], ["-n"]) { @ARGV = @$args; GetOptions( "n|name=s" => \my $name, "a|age=s" => \my $age, "s|sex=s" => \my $sex ) or die "bad options\n"; print "[$name] @ARGV\n"; } -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/