Skip to content

Instantly share code, notes, and snippets.

@dgoade
Created May 2, 2015 13:16
Show Gist options
  • Save dgoade/c104ff00ff65c0266512 to your computer and use it in GitHub Desktop.
Save dgoade/c104ff00ff65c0266512 to your computer and use it in GitHub Desktop.
Automation Scripting Essentials, Perl: Getopt::Long
#!/usr/bin/perl
use strict;
# Automation Scripting Essential Skills (https://github.com/dgoade/ase)
# Perl
# Input: Parsing command-line parameters
# Technique #1 -- Use getopt or getoptlong
use Getopt::Long;
our $Action;
our $Help;
our $LogLevel;
our $NoOp;
our $Verbose;
GetOptions (
"a|action=s" => \$Action,
"h|help" => \$Help,
"l|loglevel=s" => \$LogLevel,
"n|noop" => \$NoOp,
"v|verbose" => \$Verbose
);
print "Parameters you passed:\n";
print "action=$Action\n";
print "help=$Help\n";
print "loglevel=$LogLevel\n";
print "noop=$NoOp\n";
print "verbose=$Verbose\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment