[Perl] Getopt::Std argument list mistake?

Status
Not open for further replies.

davyzhu

Advanced Member level 1
Joined
May 23, 2004
Messages
494
Helped
5
Reputation
10
Reaction score
2
Trophy points
1,298
Location
oriental
Activity points
4,436
Hi all,

I have write a small program to test Getopt::Std.

I found when I enter
>>perl test_opt.pl -b 100 -a 50 -v
it work OK: output: minus_result is -50

But when I enter
>>perl test_opt.pl -v -b 100 -a 50
It output the help message?

Why -v must be write at the end of the argument list??

Code:
#-------------------------
use warnings;
use strict;
use Getopt::Std;

my $help = <<"EOH";
--------------------------------------------
$0: first_vector minus second_vector

Options:
	-a first_vector
	-b second_vector
	-h print help
	-v verbose
--------------------------------------------
EOH

# set out command-line options,
# requirements, and defaults.
my %options; 
getopt("a:b:hv", \%options);

die $help if exists $options{h};
die $help unless $options{a};
die $help unless $options{b};

my $first_vector = $options{a};
my $second_vector = $options{b};

my $minus_result = $first_vector - $second_vector;

if (exists $options{v}) {
    print "minus_result is $minus_result\n";
}
else {
    print "$minus_result\n";
}
#-------------------------------------

Thanks!
Davy
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…