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

The POSIX Standard - 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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Under the POSIX standard, it's also possible to use longer, more readable command-line options, preceded with a double dash, as in the
following example:

$ ls --color

The Getopt::Long.pm module provides an API for Perl developers to capture these long command-line options, and act on them within the business logic of the Perl script. This API is pretty advanced: it ignores case differences in option names, can resolve abbreviated option names to their longer counterparts (so long as they are unique), and  recognizes both single- and double-dashes as option prefixes. For purists and those who are tasked with porting legacy applications, the module also supports the older, single-character form of command-line options (but only if they belong to the alphabetic set).

There is one primary function in the Getopt::Long.pm module-GetOptions(), and it serves as the main control point for you to access the options passed to the program. You can use this to

  • read command-line options into Perl scalars, arrays or hashes,
  • create user-defined subroutines to handle specific options,
  • separate option "bundles" into individual units,
  • and configure the behaviour of the module.

More on some of these as we proceed through this tutorial.

Getopt::Long.pm is written in the best traditions of object-oriented programming, fondly known as OOP. If you're a fan of OOP, you can create a Getopt::Long object, which has its own methods and properties, and use standard OO syntax to access its functions, extend it, sub-class it, derive new hybrids from it--all kinds of good stuff, basically. In case you don't know what OOP is, you're probably not impressed. Good for you!



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PERL PROGRAMMING ARTICLES

- 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: