For example, what if you want the --length option to default to 10 when plotting but to 20 when calculating?
Solution a) Leave value undefined for now. (use topic-specific default value when you branch into that code)
my $opt_length;
GetOptions (
"length=i" => \$opt_length,
);
# call plot() or calc()
sub plot {
my $length = opt_length // 10;
...
}
sub calc {
my $length = opt_length // 20;
...
}
Solution b) Only parse the first argument to decide which route to take and then hand over the rest of @ARGV to the next level -> http://perldoc.perl.org/Getopt/Long.html#Parsing-options-from-an-arbitrary-array