Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top