Home: Perl Programming Help: Beginner:
How to use Getopt module ??

New User

Sep 16, 2012, 2:54 AM

Views: 1546
How to use Getopt module ??

hi ... can anyone tell me how to use Getopt::EvaP module and how @PDT and @MM are used ....any kind of help will be appreciated ...thanks in advance.


Sep 18, 2012, 5:18 AM

Views: 1525
Re: [mak] How to use Getopt module ??

I recommend that you use one of the standard modules (Getopt::Std or Getopt::Long) instead. If you have a special requirement that these will not meet, tell us about it.
Good Luck,


Sep 20, 2012, 8:29 AM

Views: 1515
Re: [BillKSmith] How to use Getopt module ??

In Reply To
I recommend that you use one of the standard modules (Getopt::Std or Getopt::Long) instead. If you have a special requirement that these will not meet, tell us about it.

test.pl (a sample from CPAN)


use Getopt::EvaP; # Evaluate Parameters
use subs qw/exit/;

sub exit {} # override builtin to check command line processing errors

@PDT = split /\n/, <<'end-of-PDT';
PDT sample
verbose, v: switch
command, c: string = D_SAMPLE_COMMAND, "ps -el"
scale_factor, sf: real = 1.2340896e-1
millisecond_update_interval, mui: integer = $required
ignore_output_file_column_one, iofco: boolean = TRUE
output, o: file = stdout
queue, q: key plotter, postscript, text, printer, keyend = printer
destination, d: application = `hostname`
tty, t: list of name = ("/dev/console", "/dev/tty0", "/dev/tty1")
PDTEND optional_file_list

@MM = split /\n/, <<'end-of-MM';

A sample program demonstrating typical Evaluate Parameters


sample -usage_help
sample -h
sample -full_help
sample -mui 1234
A 'switch' type parameter emulates a typical standalone
switch. If the switch is specified Evaluate Parameters
returns a '1'.
A 'string' type parameter is just a list of characters,
which must be quoted if it contains whitespace.
NOTE: for this parameter you can also create and
initialize the environment variable D_SAMPLE_COMMAND to
override the standard default value for this command
line parameter. All types except 'switch' may have a
default environment variable for easy user customization.
A 'real' type parameter must be a real number that may
contain a leading sign, a decimal point and an exponent.
An 'integer' type parameter must consist of all digits
with an optional leading sign. NOTE: this parameter's
default value is '$required', meaning that
Evaluate Parameters ensures that this parameter is
specified and given a valid value. All types except
'switch' may have a default value of '$required'.
A 'boolean' type parameter may be TRUE/YES/ON/1 or
FALSE/NO/OFF/0, either upper or lower case. If TRUE,
Evaluate Parameters returns a value of '1', else '0'.
A 'file' type parameter expects a filename. For Unix
$HOME and ~ are expanded. For evap/Perl 'stdin' and
'stdout' are converted to '-' and '>-' so they can be
used in a Perl 'open' function.
A 'key' type parameter enumerates valid values. Only the
specified keywords can be entered on the command line.
An 'application' type parameter is not type-checked in
any - the treatment of this type of parameter is
application specific. NOTE: this parameter' default
value is enclosed in grave accents (or "backticks").
Evaluate Parameters executes the command and uses it's
standard output as the default value for the parameter.
A 'name' type parameter is similar to a string except
that embedded white-space is not allowed. NOTE: this
parameter is also a LIST, meaning that it can be
specified multiple times and that each value is pushed
onto a Perl LIST variable. In general you should quote
all list elements. All types except 'switch' may be
'list of'.

EvaP \@PDT, \@MM; # evaluate parameters


Run as follows

perl test.pl -mui 10

perl test.pl -help

perl test.pl -mui 20 -command ps