use strict;
use warnings;
use Getopt::Long;
my %args;
my $result = GetOptions (
"c=s" => \&COMP1,
"t=s" => sub {
if($args{c}) {
COMP2(@_); # COMP2 will not be called if option c is null?
} else {
die 'Warning: arg -t without preceding -c: arg -t ignored';
}
},
'<>' => sub {print "\nThat is not a valid parameter\n";},
);
die "Error: argument processing did not complete successfully" unless($result);
exit(0);
sub COMP1 {
print "Option -$_[0] is value=$_[1]\n";
$args{$_[0]} = $_[1];
}
sub COMP2 {
print "Option -$_[0] is value=$_[1]\n";
$args{$_[0]} = $_[1];
}
####
$ ./test.pl -t asdf -c qwer
Warning: arg -t without preceding -c: arg -t ignored at ./test.pl line 13.
Option -c is value=qwer
Error: argument processing did not complete successfully at ./test.pl line 18.
####
use strict;
use warnings;
use Getopt::Long;
my %args;
my $result = GetOptions (
"c=s" => \&COMP1,
"t=s" => sub {
if($args{c}) {
COMP2(@_); # COMP2 will not be called if option c is null?
} else {
warn 'Error: arg -t without preceding -c: processing terminated';
die '!FINISH';
}
},
'<>' => sub {print "\nThat is not a valid parameter\n";},
);
die "Error: argument processing did not complete successfully" unless($result);
exit(0);
sub COMP1 {
print "Option -$_[0] is value=$_[1]\n";
$args{$_[0]} = $_[1];
}
sub COMP2 {
print "Option -$_[0] is value=$_[1]\n";
$args{$_[0]} = $_[1];
}
####
$ ./test.pl -t asdf -c qwer
Error: arg -t without preceding -c: processing terminated at ./test.pl line 13.
####
use strict;
use warnings;
use Getopt::Long;
my %args;
my $result = GetOptions (
"c=s" => \&COMP1,
"t=s" => sub {
if($args{c}) {
COMP2(@_); # COMP2 will not be called if option c is null?
} else {
warn 'Error: arg -t without preceding -c: processing terminated';
die '!FINISH';
}
},
'<>' => sub {print "Frobnicating $_[0]\n";},
);
die "Error: argument processing did not complete successfully" unless($result);
exit(0);
sub COMP1 {
print "Option -$_[0] is value=$_[1]\n";
$args{$_[0]} = $_[1];
}
sub COMP2 {
print "Option -$_[0] is value=$_[1]\n";
$args{$_[0]} = $_[1];
}
####
$ ./test.pl foo -t bar -c baz
Frobnicating foo
Error: arg -t without preceding -c: processing terminated at ./test.pl line 13.