Because I can't find a convenient way to check if $str
is in @array
, I'm trying to make one myself, but it is not working.
I guess it is because of the mix-up of array and string. It keeps giving 0
to $str
. Please let me know how to fix it.
use 5.010;
use strict;
use warnings;
sub ifin {
my (@array, $str) = @_;
for my $i (@array) {
if ($i eq $str) {
return 1;
}
}
return 0;
}
my @f = (1, 2, 3, 4);
my $k = 1;
print ifin(@f, $k);