This function does the same as exists does with hashes.
I plan on use it a lot.
Can it be optimized in some way?
my @a = qw/a b c d/;
my $ret = array_exists("b", @a);
sub array_exists {
my ($var, @a) = @_;
foreach my $e (@a) {
if ($var eq $e) {
return 1;
}
}
return 0;
}
You can use smart matching, available in Perl 5.10 and later:
This should be much faster than a function call.