[tpm] Command line option processing

arocker at vex.net arocker at vex.net
Sat Jan 5 13:53:10 PST 2008


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?



More information about the toronto-pm mailing list