in reply to Re^2: Comparing multiple strings
in thread Comparing multiple strings
Have you tried converting your attempts to plain English, and reading them to yourself? That may help you.
becomes "if any of a list of strings are not equal to my special string, then call the whole thing bad". When I say that out loud, it seems reasonable that your if would return true, and you would print "BAD", every time: your list of strings are not all the same string; so even if one is equal to $my1, the others aren't -- so "any" of them are "not equal to $my1", which means it will always print "BAD", unless your whole list are the same string, and match $my1.if (any { $my1 ne $_ } 'EV-1891', 'EV-DKL1') { print "BAD"; last; }
What you really seem to want is "call it bad unless there's at least one that does match". In that case, the logic could be: unless( any { $my1 eq $_ } 'EV-1891', 'EV-DKL1') { print "BAD"; last; }, or TIMTOWTDI, if( none { $my1 eq $_ } 'EV-1891', 'EV-DKL1') { print "BAD"; last; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Comparing multiple strings
by pryrt (Abbot) on Jan 15, 2019 at 22:42 UTC |