Home arrow Perl Programming arrow Page 3 - Processing Command Line Options with PERL

Down To Work - Perl

Over the course of the next few pages, I will introduce you to one of the more interesting modules in the Perl pantheon, the Getopt::Long.pm module. This module provides a simple API to parse options passed to your Perl scripts at the command line and convert them into Perl scalars or arrays.

  1. Processing Command Line Options with PERL
  2. The POSIX Standard
  3. Down To Work
  4. GetOptions() Function
  5. Half-Life
  6. Getopt::Long.pm
  7. Opting In
  8. Negative Reinforcement
  9. Hashing It Up
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 58
March 31, 2004

print this article



Now, with the hard sell out of the way, let's get down to the nitty-gritty of how Getopt::Long.pm works. Consider the following simple example:

# import module
use Getopt::Long;
# set default value for option
$debug = 0;
# get value of debug flag
$result = GetOptions ("debug" => $debug);  
# print value
print "Debug flag is $debug";

Now, try running this code as is:

$ ./script.pl
Debug flag is 0

And then try running it after adding a "--debug" command-line option:

$ ./script.pl --debug
Debug flag is 1

As you can see, the Perl code now recognizes the "--debug" flag on the command line, and sets a Boolean variable to true within the script.

>>> More Perl Programming Articles          >>> More By icarus, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Perl Turns 25
- Lists and Arguments in Perl
- Variables and Arguments in Perl
- Understanding Scope and Packages in Perl
- Arguments and Return Values in Perl
- Invoking Perl Subroutines and Functions
- Subroutines and Functions in Perl
- Perl Basics: Writing and Debugging Programs
- Structure and Statements in Perl
- First Steps in Perl
- Completing Regular Expression Basics
- Modifiers, Boundaries, and Regular Expressio...
- Quantifiers and Other Regular Expression Bas...
- Parsing and Regular Expression Basics
- Hash Functions

Developer Shed Affiliates


Dev Shed Tutorial Topics: