Use Getopt (see Perl manual) for options. If you need options then you must also add a USAGE section to your code. An example of a USAGE is given below:

(my $progname = $0) =~ s'^.*/'';   # strip path components, if any
my  $allurl =
      'http://www-iepm.slac.stanford.edu/cgi-wrap/pingtable.pl?format=tsv'
    . '&file=minimum_rtt&by=by-node&size=100&tick=allmonthly&from=WORLD'
    . '&to=WORLD&ex=none&dataset=hep&percentage=any';
my $dir    = "/afs/slac.stanford.edu/package/netmon/pinger/pingerDB/code/pingermanagement";
my $file   = "$dir/data/minrtt";
my $allfile="$dir/minrtt2";
my $version="0.6, 5/15/06, Waqar and Les";
my $url = 'http://www-iepm.slac.stanford.edu/cgi-wrap/pingtable.pl?format=tsv' ### by default , get las
        . '&file=minimum_rtt&by=by-node&size=100&tick=last60days&from=WORLD'
        . '&to=WORLD&ex=none&dataset=hep&percentage=any';

my $USAGE = "Function:
        This script downloads the PingER data and saves it
Usage:\t $progname [opts]
        Opts:
        [i -allmonthly]
        [-v]
Where:
        allmonthly selects the URL for the input and output, the defaults are:
        input URL:
        $url
        output file:
        $file
        if allmonthly is specified then the input URL is
        $allurl
        and the output file is
        $allfile
        -v provides this output.
Version: $version
";
...
require "getopts.pl";
our ($opt_i, $opt_v);
&Getopts('i:v');
if(defined($opt_v)) {print $USAGE; exit 1;}
  • No labels