use Getopt::Std; # set up informative strings my $usage = "$0 version $VERSION by -= $AUTHOR =- use -h for help"; my $help = "use $0 {-a | -o} use $0 -a to "AND" your criteria use $0 -o to "OR" your criteria "; #when you call getopts, you pass a string and a hash ref. # the string defines what switches you accept, and the hash # gets filled in accordingly. For instance, if someone put # in a -h here, $options{h} would be set to 1 (true). my %options; getopts('huao', \%options); # in this case, I'm assuming either and "and" or "or" is # required. $options{u}=1 unless %options && ($options{a} || $options{o}); #it's more readable to break this into two tests #we need to make sure someone didn't put in -a and -o $options{u}=1 if ($options{a} && $options{o}); # I haven't done it this way in a while, but IIRC # anything not handled by getopts gets left in ARGV # Therefore, we need to make sure that there are two # options left (two criteria) $options{u}=1 unless $#ARGV==2; # now here we go. for any of our test cases we would # have set $options{u}, so if the command line was bad # it will get caught and exited here. if ($options{h} || $options{u}){ print "$usage\n"; print "$help\n" if ($options{h}); exit 0; }