in reply to searching through array for multiple patterns
cheersuse strict; use warnings; my @commands_run = qw(first second clock fourth); #join all elements of the array my $all_commands = join '#', @commands_run; if ($all_commands =~m/clock/) { print "\n Test -- found pattern -- \n"; } else { print "\n Test -- did not find pattern -- \n"; } #use a flag to indicate a match my $found = 0; foreach (@commands_run) { if($_ =~m/clock/) { $found++; } } $found ? print "\n Test -- found pattern -- \n" : print "\n Test -- did not find pattern -- \n";
si_lence
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: searching through array for multiple patterns
by skirnir (Monk) on Jul 16, 2009 at 08:41 UTC | |
|
Re^2: searching through array for multiple patterns
by si_lence (Deacon) on Jul 16, 2009 at 09:32 UTC |