Problem: I've got a script that can be called in one of the following ways:
./script.pl -a
./script.pl [-w] -<i|d|r|t>
Meaning, the -w
flag is optional, but either -i
or -d
or -r
or -t
must be specified.
If the user doesn't call the script in any of those ways, the function usage
should be called.
My attempt:
sub fInv
{
print "fInv"."\n";
}
sub fDisp
{
print "fDisp"."\n";
}
sub fRanking
{
print "fRanking"."\n";
}
sub fTickets
{
print "fTickets"."\n";
}
sub usage
{
print "Usage shown here.\n";
}
%options = (i => \&fInv, d => \&fDisp, r => \&fRanking, t => \&fTickets);
$write = 0;
GetOptions("a" => \&usage)
or GetOptions("w" => \$write,
keys($options) => \&options) # This is clearly wrong
or die usage;