If both strings have spaces or neither has spaces, then do something.
my $with_spaces = $a =~ / / and $b =~ / /;
my $no_spaces = $a !~ / / and $b !~ / /;
if ($with_spaces or $no_spaces) {
dosomething();
}
But this code gives an error:
Useless use of negative pattern binding (!~) in void context.
Did I do something wrong here?
The lines:
my $with_spaces = $a =~ / / and $b =~ / /;
my $no_spaces = $a !~ / / and $b !~ / /;
are equivalent to:
(my $with_spaces = $a =~ / /) and ($b =~ / /);
(my $no_spaces = $a !~ / /) and ($b !~ / /);
Either use &&
instead of and
, or add parentheses to change the precedence:
my $with_spaces = $a =~ / / && $b =~ / /;
my $no_spaces = ($a !~ / / and $b !~ / /);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With