How to check what is defined by only one of -a or -b or -c ?
So, not together -a -b , neither -a -c , nor -b -c , nor -a -b -c .
Now
use strict; use warnings; use Carp; use Getopt::Std; our($opt_a, $opt_b, $opt_c); getopts("abc"); croak("Options -a -b -c are mutually exclusive") if ( is_here_multiple($opt_a, $opt_c, $opt_c) ); sub is_here_multiple { my $x = 0; foreach my $arg (@_) { $x++ if (defined($arg) || $arg); } return $x > 1 ? 1 : 0; }
The above works, but not very elegantly.
There is a similar question here, but this is different, because checking two exclusive values ββis easy - but here are a few.
source share