I want to find out if $anything is in some @array. I wrote this, but feel (due to my Perl un-skills) that there may be a better way. Ideas/comments?
use strict; my $input = <>; chomp $input; my @test_array = qw(1 2 3 4 5 6 7 8 9); if ( member($input, \@test_array) ) { print "Hey, there's one of those in there!\n\n"; } else { print "Better luck next time: it's not in there.\n\n"; } sub member { my $possible = $_[0]; my $array_ref = $_[1]; foreach my $member ( @{$array_ref} ) { if ( $member eq $possible ) { return "1"; } } return "0"; }
-- I'm a solipsist, and so is everyone else. (think about it)
In reply to better way to find list members? by jptxs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |