- or download this
my $number_of_true_variables = grep { $_ } $x, $y, $z;
if ( $number_of_true_variables == 1 ) {
print "Exactly one variable set\n";
}
- or download this
sub number_of_true_variables {
return scalar grep { $_ } @_;
...
if ( number_of_true_variables( $x, $y, $z ) == 1 ) {
print "Exactly one variable set\n";
}
- or download this
sub exactly_one_is_set {
my $number_of_true_variables = grep { $_ } @_;
...
if ( exactly_one_is_set( $x, $y, $z ) ) {
print "Exactly one variable set\n";
}