I'm not sure I understand your question completely. If you want to print your 'found / not found' once, i.e. whether the pattern is present or absent in the array you could either join the array into a string an match the string (just make sure you don't create a match by joining the elements of the array) or have a flag that indicates a match and print your message after looping over your array.
use 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";
cheers
si_lence
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|