find if array contains element





0
Date Submitted Sat. Mar. 8th, 2008 1:41 PM
Revision 1 of 1
Beginner chorny
Tags find | Grep | Perl
Comments 0 comments
Usage:
found('asdf',@array);

P.S. In perl 5.10 can be written as
use 5.010;
'asdf'~~@array;

sub found($@) {
 my $a=shift;
 foreach (@_) {
  return 1 if $a eq $_;
 }
 return 0;
}
 

Alexandr Ciornii

chorny.net
---
Sasha Chorny, http://chorny.net

Comments

There are currently no comments for this snippet.

Voting

Votes Up


Votes Down