Given an array @A we want to check if the element $B is in it. One way is to say this:
Foreach $element (@A){
if($element eq $B){
print "$B is in array A";
}
}
However when it gets to Perl, I am thinking always about the most elegant way. And this is what I am thinking:
Is there a way to find out if array A contains B if we convert A to a variable string and use
index(@A,$B)=>0
Is that possible?
There are many ways to find out whether the element is present in the array or not:
Using foreach
Using Grep:
Using List::Util module
Using Hash initialised by a Slice
Using Hash initialised by map