Perl Programming Page 2 - Processing Command Line Options with PERL |
Under the POSIX standard, it's also possible to use longer, more readable command-line options, preceded with a double dash, as in the
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
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!
blog comments powered by Disqus |