6 @EXPORT = qw(getopt getopts);
8 # $RCSfile: getopt.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:23:58 $
10 # Process single-character switches with switch clustering. Pass one argument
11 # which is a string containing all switches that take an argument. For each
12 # switch found, sets $opt_x (where x is the switch name) to the value of the
13 # argument, or 1 if no argument. Switches which take an argument don't care
14 # whether there is a space between the switch and the argument.
17 # getopt('oDI'); # -o, -D & -I take arg. Sets opt_* as a side effect.
20 local($argumentative) = @_;
21 local($_,$first,$rest);
22 local $Exporter::ExportLevel;
24 while (@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
25 ($first,$rest) = ($1,$2);
26 if (index($argumentative,$first) >= 0) {
34 eval "\$opt_$first = \$rest;";
35 push( @EXPORT, "\$opt_$first" );
38 eval "\$opt_$first = 1;";
39 push( @EXPORT, "\$opt_$first" );
48 $Exporter::ExportLevel++;
53 # getopts('a:bc'); # -a takes arg. -b & -c not. Sets opt_* as a
57 local($argumentative) = @_;
58 local(@args,$_,$first,$rest);
60 local $Exporter::ExportLevel;
62 @args = split( / */, $argumentative );
63 while(@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
64 ($first,$rest) = ($1,$2);
65 $pos = index($argumentative,$first);
67 if($args[$pos+1] eq ':') {
73 eval "\$opt_$first = \$rest;";
74 push( @EXPORT, "\$opt_$first" );
77 eval "\$opt_$first = 1";
78 push( @EXPORT, "\$opt_$first" );
88 print STDERR "Unknown option: $first\n";
98 $Exporter::ExportLevel++;