I am investigating the use of the getopt method with a dispatch table to process command line arguments. I have found a lot information on the web regarding the topic, but I can't get the following simple example to work:
#!/usr/local/bin/perl # Argument options using Dispatch Tables use strict; use Getopt::Std; my %opts = (); getopts ('dhp', \%opts); %opts = ( # For each option, call appropriate subroutine. "-h" => \&help, "-d" => sub {print "\nRun DEV COMPARE\n";}, "-p" => \&PROD, "_default_" => \&default, ); sub PROD {print "\nRun Production COMPARE\n";} sub help {print "\nHelp text\n";} sub default {print "\nThat is not a valid option\n";}
The code runs without error, but does nothing when I enter any of the valid options that I defined as arguments. Any help would be appreciated. Thank you.
In reply to Parsing options with Getopt & Dispatch Table by MKJ747
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |