One way would be to put all the strings you want to match (or negative match) in a hash so that you can check for their existance:
my @invalid_list = qw< John Simon Mathias Aerith Bob >; my @test = qw< Alice Bob John Doe >; my %invalid = map { $_ => 1 } @invalid_list; for my $name (@test) { print "$name\n" unless exists $invalid{$name}; }
Or, as proposed by tobyink, you can use List::Util:
(There's also notall, but it would have required a triple negation in this case).use List::Util qw( none all any ); for my $name (@test) { print "None > $name\n" if none { $name eq $_ } @invalid_list; print "Any > $name\n" unless any { $name eq $_ } @invalid_list; print "All > $name\n" if all { $name ne $_ } @invalid_list; }
In reply to Re: Comparing multiple strings
by Eily
in thread Comparing multiple strings
by bigup401
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |