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
How about $str ~~ @arr
in a smartmatch? That's available in Perl 5.10.
use 5.010;
use strict;
use warnings;
my $str = 'three';
my @arr = qw(zero one two three four);
my @badarr = qw(zero one two four eight);
say '$str ', $str ~~ @arr? 'is' : 'is not', ' in $arr.';
say '$str ', $str ~~ @badarr? 'is' : 'is not', ' in $badarr.';
Output, as expected:
$str is in $arr.
$str is not in $badarr.