I find myself writing perl member functions since there is no one built in…
sub member { my $elm = shift; my @lst = @_; for( my $i=0; $i < @lst; $i++) { return 1 if lc($elm) eq lc($lst[$i]); } return 0; }
I like this one better... it reads better I think, but sadly I believe "foreach" will disappear in Perl 6 is it not?
sub member { my $elm = shift; my @lst = @_; foreach my $item (@lst) { return 1 if lc($elm) eq lc($item); } return 0; }
Update: Now, if you use "use 5.010;" (which I strongly recommend that you do!) (of course running Perl 5.10 or higher) this can be done with the very cool "smart match" operator "~~".
$scalar ~~ @list; # Member with new smart match operator in Perl 5.10 or higher.