in reply to check if a value is in a given set
Elegant? Hard to say...
Smartmatch:
perl -e 'my @t=qw/banana plum apple strawberry pea/;my $fruit="apple"; +print (($fruit~~\@t)?"yes":"no");' yes
Undef hash:
perl -e 'my @t=qw/banana plum apple strawberry pea/;my $fruit="apple"; +my %in;undef @in{@t};print ((exists $in{$fruit})?"yes":"no");' yes
for,next,last:
perl -e 'my @t=qw/banana plum apple strawberry pea/;my $fruit="apple"; +for my $f (@t) {next if $fruit ne $f;print "yes";last}' yes
grep?
#no, not efficient
|
|---|