MKJ747 has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing options with Getopt & Dispatch Table
by toolic (Bishop) on Feb 17, 2011 at 15:24 UTC | |
|
Re: Parsing options with Getopt & Dispatch Table
by cjb (Friar) on Feb 17, 2011 at 15:31 UTC | |
by MKJ747 (Acolyte) on Feb 17, 2011 at 15:50 UTC | |
by MKJ747 (Acolyte) on Feb 17, 2011 at 16:57 UTC | |
by broomduster (Priest) on Feb 18, 2011 at 15:56 UTC | |
by MKJ747 (Acolyte) on Feb 22, 2011 at 13:30 UTC |