home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Book HomeJava and XSLTSearch this book

8.118. Getopt::Std

Processes single-character, command-line options with option clustering. Exports two functions, which analyze @ARGV, extract information about the options, and return this information to your program in a set of variables. Processing of @ARGV stops when an argument without a leading - is encountered, if that argument is not associated with a preceding option. Otherwise, @ARGV is processed to the end and left empty.


getopt ('switches'[, \%opts])

switches is a string of the command-line options that take arguments. For each option, getopt sets $opt_x (in which x is the switch) to the value entered as an argument. If \%optsis specified, it is a reference to a hash in which getopt sets the key to the name of the switch and the value to the argument (and the $opt_ variables are not set).


getopts ('switches'[, \%opts])

Like getopt, except that all valid options are included in switches, and options that take an argument are followed by a colon (:). For example:

getopt('oDI')    # -o, -D, & -I take arguments; there may 
                 # be other options
getopts('o:DI')  # -o, -D, and -I are the only valid 
                 # options; only -o takes an argument

\%opts means the same as with getopt.

Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.