C<Getopt::Simple> - Provide a simple wrapper around Getopt::Long.


NAME

Getopt::Simple - Provide a simple wrapper around Getopt::Long.


SYNOPSIS

        use Getopt::Simple;
        # Or ...
        # use Getopt::Simple qw($switch);
        my($options) =
        {
        help =>
                {
                type    => '',
                env     => '-',
                default => '',
#               verbose => '',      # Not needed on every key.
                order   => 1,
                },
        username =>
                {
                type    => '=s',    # As per Getopt::Long.
                env     => '$USER', # Help text.
                default => $ENV{'USER'} || 'RonSavage', # In case $USER is undef.
                verbose => 'Specify the username on the remote machine',
                order   => 3,       # Help text sort order.
                },
        password =>
                {
                type    => '=s',
                env     => '-',
                default => 'password',
                verbose => 'Specify the password on the remote machine',
                order   => 4,
                },
        };
        my($option) = Getopt::Simple -> new();
        if (! $option -> getOptions($options, "Usage: testSimple.pl [options]") )
        {
                exit(-1);       # Failure.
        }
        print "username: $$option{'switch'}{'username'}. \n";
        print "password: $$option{'switch'}{'password'}. \n";
        # Or, after 'use Getopt::Simple qw($switch);' ...
        # print "username: $$switch{'username'}. \n";
        # print "password: $$switch{'password'}. \n";


DESCRIPTION

Getopt::Simple is a pure Perl module.

The Getopt::Simple module provides a simple way of specifying:


Distributions

This module is available both as a Unix-style distro (*.tgz) and an ActiveState-style distro (*.ppd). The latter is shipped in a *.zip file.

See http://savage.net.au/Perl-modules.html for details.

See http://savage.net.au/Perl-modules/html/installing-a-module.html for help on unpacking and installing each type of distro.


Constructor and initialization

new(...) returns a Getopt::Simple object.

This is the class's contructor.

Usage: Getopt::Simple -> new().

This method does not take any parameters.


The dumpOptions() function

dumpOptions() prints all your option's keys and their current values.

dumpOptions() does not return anything.


The getOptions() function

The getOptions() function takes 4 parameters:

getOptions() returns 0 for failure and 1 for success.


The hash ref of command line switches


The helpOptions() function

helpOptions() prints nicely formatted help text.

helpOptions() does not return anything.


The $$classRef{'switch'} hash reference

Command line option values are accessed in your code by dereferencing the hash reference $$classRef{'switch'}. Two examples are given above, under synopsis.

Alternately, you can use the hash reference $switch. See below.


The $switch hash reference

Command line option values are accessed in your code by dereferencing the hash reference $switch. Two examples are given above, under synopsis.

Alternately, you can use the hash reference $$classRef{'switch'}. See above.


WARNING re Perl bug

As always, be aware that these 2 lines mean the same thing, sometimes:

The problem is the spaces around the ->. Inside double quotes, ``...'', the first space stops the dereference taking place. Outside double quotes the scanner correctly associates the $self token with the {'thing'} token.

I regard this as a bug.


AUTHOR

Getopt::Simple was written by Ron Savage <ron@savage.net.au> in 1997.


LICENCE

Australian copyright (c) 1997-2002 Ron Savage.

        All Programs of mine are 'OSI Certified Open Source Software';
        you can redistribute them and/or modify them under the terms of
        The Artistic License, a copy of which is available at:
        http://www.opensource.org/licenses/index.html
 C<Getopt::Simple> - Provide a simple wrapper around Getopt::Long.