March 2001
Intermediate to advanced
288 pages
4h 56m
English
There's an alternative way of option parsing using the core module Getopt::Long:
use Getopt::Long;
use constant WEB => 1;
use constant SQL => 2;
use constant REG => 4;
my %dbg_flag = (
WEB => WEB,
SQL => SQL,
REG => REG);
my %dbg;
GetOptions(\%dbg, "D=s@");
my $DEBUG = WEB | REG unless $dbg{D};
$DEBUG |= $dbg_flag{$_}
|| die "Unknown debug flag $_\n"
foreach @{$dbg{D}};
(We've shown only the option-parsing part.) This has a slightly different interface; instead of separating multiple values with commas, we must repeat the -D flag:
% whizzbang.pl -D WEB -D REG
(We could also say “-D=WEB -D=REG”.)
Getopt::Long permits many more choices than this, of course. If you have a complex program (particularly one worked ...