Perl inarray function
April 18th, 2008 Posted in ProgramareTaken from: http://assasiner.wordpress.com/2006/12/03/is-in-array/trackback/
You can use grep for this task like this: if(grep $_ eq $string, @array)
or if you want regular expressions: if(grep /$string/, @array)
As an example:
#!/usr/bin/perl
my $string = ‘fin_helm’;
my @array = qw/full_plate manteau boots two_handed_sword fin_helm/;
if(grep $_ eq $string, @array)
{
print “$string is in the arrayâ€;
}