I\'m looking for presence of an element in a list.
In Python there is an in
keyword and I would do something like:
if element in list:
If you plan to do this many times, you can trade-off space for lookup time:
#!/usr/bin/perl
use strict; use warnings;
my @array = qw( one ten twenty one );
my %lookup = map { $_ => undef } @array;
for my $element ( qw( one two three ) ) {
if ( exists $lookup{ $element }) {
print "$element\n";
}
}
assuming that the number of times the element appears in @array
is not important and the contents of @array
are simple scalars.