#! /usr/bin/perl -w use strict; # What we're trying to find my $target = shift; # Flag to hold found status my $found; # List to search through my @words = qw/bcd efg hij klm/; # Look through the list foreach (@words) { # This will be true if they match $found = $target eq $_; # We found one, get out of this loop early last if $found; } # Print if nothing was found print "$target not found$/" unless $found;
But you just can't beat eieio's use of grep() below. Fantastic, ++
In reply to Re^3: does not exist in an array
by dmorelli
in thread does not exist in an array
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |