{
    "mode": "perldoc",
    "parameter": "Getopt::Simple",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Getopt%3A%3ASimple/json",
    "generated": "2026-06-09T12:51:32Z",
    "synopsis": "use Getopt::Simple;\n# Or ...\n# use Getopt::Simple qw($switch);\nmy($options) =\n{\nhelp =>\n{\ntype    => '',\nenv     => '-',\ndefault => '',\n#               verbose => '',      # Not needed on every key.\norder   => 1,\n},\nusername =>\n{\ntype    => '=s',    # As per Getopt::Long.\nenv     => '$USER', # Help text.\ndefault => $ENV{'USER'} || 'RonSavage', # In case $USER is undef.\nverbose => 'Specify the username on the remote machine',\norder   => 3,       # Help text sort order.\n},\npassword =>\n{\ntype    => '=s',\nenv     => '-',\ndefault => 'password',\nverbose => 'Specify the password on the remote machine',\norder   => 4,\n},\n};\nmy($option) = Getopt::Simple -> new();\nif (! $option -> getOptions($options, \"Usage: testSimple.pl [options]\") )\n{\nexit(-1);       # Failure.\n}\nprint \"username: $$option{'switch'}{'username'}. \\n\";\nprint \"password: $$option{'switch'}{'password'}. \\n\";\n# Or, after 'use Getopt::Simple qw($switch);' ...\n# print \"username: $$switch{'username'}. \\n\";\n# print \"password: $$switch{'password'}. \\n\";",
    "sections": {
        "NAME": {
            "content": "\"Getopt::Simple\" - Provide a simple wrapper around Getopt::Long.\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Getopt::Simple;\n\n# Or ...\n# use Getopt::Simple qw($switch);\n\nmy($options) =\n{\nhelp =>\n{\ntype    => '',\nenv     => '-',\ndefault => '',\n#               verbose => '',      # Not needed on every key.\norder   => 1,\n},\nusername =>\n{\ntype    => '=s',    # As per Getopt::Long.\nenv     => '$USER', # Help text.\ndefault => $ENV{'USER'} || 'RonSavage', # In case $USER is undef.\nverbose => 'Specify the username on the remote machine',\norder   => 3,       # Help text sort order.\n},\npassword =>\n{\ntype    => '=s',\nenv     => '-',\ndefault => 'password',\nverbose => 'Specify the password on the remote machine',\norder   => 4,\n},\n};\n\nmy($option) = Getopt::Simple -> new();\n\nif (! $option -> getOptions($options, \"Usage: testSimple.pl [options]\") )\n{\nexit(-1);       # Failure.\n}\n\nprint \"username: $$option{'switch'}{'username'}. \\n\";\nprint \"password: $$option{'switch'}{'password'}. \\n\";\n\n# Or, after 'use Getopt::Simple qw($switch);' ...\n# print \"username: $$switch{'username'}. \\n\";\n# print \"password: $$switch{'password'}. \\n\";\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "\"Getopt::Simple\" is a pure Perl module.\n\nThe \"Getopt::Simple\" module provides a simple way of specifying:\n\n*   Command line switches\n\n*   Type information for switch values\n\n*   Default values for the switches\n\n*   Help text per switch\n",
            "subsections": []
        },
        "Distributions": {
            "content": "This module is available both as a Unix-style distro (*.tgz) and an ActiveState-style distro\n(*.ppd). The latter is shipped in a *.zip file.\n\nSee http://savage.net.au/Perl-modules.html for details.\n\nSee http://savage.net.au/Perl-modules/html/installing-a-module.html for help on unpacking and\ninstalling each type of distro.\n",
            "subsections": []
        },
        "Constructor and initialization": {
            "content": "",
            "subsections": [
                {
                    "name": "new",
                    "content": "This is the class's contructor.\n\nUsage: Getopt::Simple -> new().\n\nThis method does not take any parameters.\n\nThe \"dumpOptions()\" function\n\"dumpOptions()\" prints all your option's keys and their current values.\n\n\"dumpOptions()\" does not return anything.\n\nThe \"getOptions()\" function\nThe \"getOptions()\" function takes 4 parameters:\n\n*   A hash ref defining the command line switches\n\nThe structure of this hash ref is defined in the next section.\n\nThis parameter is mandatory.\n\n*   A string to display as a help text heading\n\nThis parameter is mandatory.\n\n*   A Boolean. 0 = (Default) Use case-sensitive switch names. 1 = Ignore case\n\nThis parameter is optional.\n\n*   A Boolean. 0 = Return after displaying help. 1 = (Default) Terminate with exit(0) after\ndisplaying help\n\nThis parameter is optional.\n\n\"getOptions()\" returns 0 for failure and 1 for success.\n"
                }
            ]
        },
        "The hash ref of command line switches": {
            "content": "*   Each key in the hash ref is the name of a command line switch\n\n*   Each key points to a hash ref which defines the nature of that command line switch\n\nThe keys and values of this nested hash ref are as follows.\n\n*   default => 'Some value'\n\nThis key, value pair is mandatory.\n\nThis is the default value for this switch.\n\nExamples:\n\ndefault => '/users/home/dir'\ndefault => $ENV{'REMOTEHOST'} || '127.0.0.1'\n\n*   env => '-' || 'Some short help text'\n\nThis key, value pair is mandatory.\n\nThis is help test, to indicate that the calling program can use an environment variable\nto set the default value of this switch.\n\nUse '-' to indicate that no environment variable is used.\n\nExamples:\n\nenv => '-'\nenv => '$REMOTEHOST'\n\nNote the use of ' to indicate we want the $ to appear in the output.\n\n*   type => 'Types as per Getopt::Long'\n\nThis key, value pair is mandatory.\n\nThis is the type of the command line switch, as defined by Getopt::Long.\n\nExamples:\n\ntype => '=s'\ntype => '=s@',\n\n*   verbose => 'Some long help text'\n\nThis key, value pair is optional.\n\nThis is long, explanatory help text which is displayed below the help containing the\nthree columns of text: switch name, env value, default value.\n\nExamples:\n\nverbose => 'Specify the username on the remote machine',\nverbose => 'Specify the home directory on the remote machine'\n\n*   order => \\d+\n\nThis key, value pair is mandatory.\n\nThis is the sort order used to force the help text to display the switches in a specific\norder down the page.\n\nExamples:\n\norder => 1\norder => 9\n\nThe \"helpOptions()\" function\n\"helpOptions()\" prints nicely formatted help text.\n\n\"helpOptions()\" does not return anything.\n\nThe $$classRef{'switch'} hash reference\nCommand line option values are accessed in your code by dereferencing the hash reference\n$$classRef{'switch'}. Two examples are given above, under synopsis.\n\nAlternately, you can use the hash reference $switch. See below.\n\nThe $switch hash reference\nCommand line option values are accessed in your code by dereferencing the hash reference\n$switch. Two examples are given above, under synopsis.\n\nAlternately, you can use the hash reference $$classRef{'switch'}. See above.\n\nWARNING re Perl bug\nAs always, be aware that these 2 lines mean the same thing, sometimes:\n\n*   $self -> {'thing'}\n\n*   $self->{'thing'}\n\nThe problem is the spaces around the ->. Inside double quotes, \"...\", the first space stops the\ndereference taking place. Outside double quotes the scanner correctly associates the $self token\nwith the {'thing'} token.\n\nI regard this as a bug.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "\"Getopt::Simple\" was written by Ron Savage *<ron@savage.net.au>* in 1997.\n",
            "subsections": []
        },
        "LICENCE": {
            "content": "Australian copyright (c) 1997-2002 Ron Savage.\n\nAll Programs of mine are 'OSI Certified Open Source Software';\nyou can redistribute them and/or modify them under the terms of\nThe Artistic License, a copy of which is available at:\nhttp://www.opensource.org/licenses/index.html\n",
            "subsections": []
        }
    },
    "summary": "\"Getopt::Simple\" - Provide a simple wrapper around Getopt::Long.",
    "flags": [],
    "examples": [],
    "see_also": []
}