* Tong * wrote:
for Perl functions to handle dozens of switches like the 'ls' or 'sort'
command does.
It depends on whether you're talking about perl functions or
perl commands.
For a perl function, arrange it so that one of the arguments
to the function is a reference to a hash, and put all the options
and values in that hash.
For a perl command, which needs to parse options from the
command line, "use Getopt::Std;" is one module that will work.
Example:
use Getopt::Std;
#options: -s = number of seconds (or minutes) to between checks (default 3s)
my %opts; getopts('c:dnrs:t:z',\%opts);
my $debug = $opts{d} || 0;
my $sleep = $opts{s} || DefaultSleep; $sleep = m2s($sleep);
my $timecount = $opts{c} || DefaultCount;
$timecount = m2s($opts{t}) / $sleep if $opts{t};
my $showzero = $opts{z} || (@ARGV == 1 and -f $ARGV[0]);
my $check_r = $opts{r} || 0; # rsync/restore
test_num(-3..19) if $opts{n}; # -n for debugging num()
-Joe