Using logical OR or AND works fine in if-conditions. but you most likely don't want to use the /g option in the regex match. Reason is this:
my $string = "foo:bar:baz:quux"; for (1..10) { print "$_\n"; if ($string=~m/:/g || length($string)!=16) { print "Either : already in string on the length is invalid\n"; } } __END__ 1 Either : already in string on the length is invalid 2 Either : already in string on the length is invalid 3 Either : already in string on the length is invalid 4 5 Either : already in string on the length is invalid 6 Either : already in string on the length is invalid 7 Either : already in string on the length is invalid 8 9 Either : already in string on the length is invalid 10 Either : already in string on the length is invalid
Note that it doesn't match on the 4th and 8th iteration. See the description of the match operator in perlop for why.
In reply to Re: How to insert || and && in an if loop
by Eliya
in thread How to insert || and && in an if loop
by perl514
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |