use warnings;
use strict;
use Getopt::Long;
my @actions;
GetOptions(
first => sub { push @actions, \&first },
second => sub { push @actions, \&second },
) or die "Invalid options passed to $0\n";
sub first {
print "Processing sub first\n";
}
sub second {
print "Processing sub second\n";
}
$_->() for @actions;
__END__
$ perl 11140961c.pl --first --second --first --second --second --first
Processing sub first
Processing sub second
Processing sub first
Processing sub second
Processing sub second
Processing sub first
$ perl 11140961c.pl --first --second --year --first --second --second --first
Unknown option: year
Invalid options passed to 11140961c.pl
####
use warnings;
use strict;
use Getopt::Long;
my $do_first = 0;
sub first { $do_first = 1 }
my $do_second = 0;
sub second { $do_second = 1 }
GetOptions(first=>\&first, second=>\&second)
or die "Invalid options passed to $0\n";
if ($do_first) { print "First!\n" }
if ($do_second) { print "Second!\n" }
__END__
$ perl 11140961.pl --first --second --first --second --second --first
First!
Second!
$ perl 11140961.pl --first --second --year --first --second --second --first
Unknown option: year
Invalid options passed to 11140961.pl
####
use warnings;
use strict;
use Getopt::Long;
my @actions;
sub first { push @actions, 'first' }
sub second { push @actions, 'second' }
GetOptions(first=>\&first, second=>\&second)
or die "Invalid options passed to $0\n";
for my $act (@actions) {
if ($act eq 'first')
{ print "First!\n" }
elsif ($act eq 'second')
{ print "Second!\n" }
else { die $act } # shouldn't happen
}
__END__
$ perl 11140961b.pl --first --second --first --second --second --first
First!
Second!
First!
Second!
Second!
First!
$ perl 11140961b.pl --first --second --year --first --second --second --first
Unknown option: year
Invalid options passed to 11140961b.pl