[tpm] Command line option processing
Indy Singh
indy at indigostar.com
Sat Jan 5 14:31:38 PST 2008
Here is one way to do it:
#!/usr/bin/perl -w
use strict;
use Getopt::Long;
my %opt;
GetOptions(
"v" => \$opt{verbose},
"test" => \$opt{test},
"d" => \$opt{debug},
"debug" => \$opt{debug},
);
if ($opt{verbose}) {
print "VERBOSE\n";
}
else {
print "quiet\n";
}
Indy Singh
IndigoSTAR Software -- www.indigostar.com
----- Original Message -----
From: <arocker at vex.net>
To: <tpm at to.pm.org>
Sent: Saturday, January 05, 2008 4:53 PM
Subject: [tpm] Command line option processing
>
> I'm trying to implement a simple check of a command line option (just
> present or absent, no arguments). The shell equivalent, which works,
> is:
>
> while getopts v opt
> do
> case $opt
> in
> v) echo "Hi"
> ;;
> esac
> done
>
> The perl, which doesn't:
>
> #! /usr/bin/perl
> use warnings;
> use Getopt::Std;
>
> getopt ("v"); # primitive help facility -v is only option
>
> if ( $Getopt::Std::opt_v ) {
> print Hi\n";
> }
>
> and changing the test to if ( $opt ) doesn't do any better.
>
> I've delved into the Camel, the Cookbook, Nutshell and every other
> grimoire I can find, so public humiliation is the only route left.
> What
> idiotic error am I making?
>
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm
More information about the toronto-pm
mailing list