1 ;# getopts.pl - a better getopt.pl
3 # This library is no longer being maintained, and is included for backward
4 # compatibility with Perl 4 programs which may require it.
6 # In particular, this should not be used as an example of modern Perl
7 # programming techniques.
9 # Suggested alternatives: Getopt::Long or Getopt::Std
11 warn( "The 'getopts.pl' legacy library is deprecated and will be"
12 . " removed in the next major release of perl. Please use the"
13 . " Getopt::Long or Getopt::Std module instead." );
16 ;# do Getopts('a:bc'); # -a takes arg. -b & -c not. Sets opt_* as a
20 local($argumentative) = @_;
21 local(@args,$_,$first,$rest);
25 @args = split( / */, $argumentative );
26 while(@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
27 ($first,$rest) = ($1,$2);
28 $pos = index($argumentative,$first);
30 if($args[$pos+1] eq ':') {
33 ++$errs unless(@ARGV);
37 push(\@opt_$first, \$rest);
38 if (!defined \$opt_$first or \$opt_$first eq '') {
39 \$opt_$first = \$rest;
42 \$opt_$first .= ' ' . \$rest;
47 eval "\$opt_$first = 1";
57 print STDERR "Unknown option: $first\n";