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:
1 2 3 4 5 6 7 | #!/usr/bin/perl my $string = "in_helm"; my @array = qw/full_plate manteau boots two_handed_sword fin_helm/; if(grep $_ eq $string, @array) { print "$string is in the array"; } |