in reply to searching through array for multiple patterns

You code is searching through the array @commands_run, I am puzzled by your reference to "line".

if it finds pattern somewhere in the array and not whether it finds it in a line ( if that makes sense)

Sorry, but its does not make sense to me. Even if your array contains multi-line records, if it is on a line then it is in the array, you are not looking anywhere else. Maybe you need to post more code?

Replies are listed 'Best First'.
Re^2: searching through array for multiple patterns
by sqspat (Acolyte) on Jul 16, 2009 at 07:59 UTC
    Hi Presently the code searches through each line looking for the pattern and prints success statement if it finds in a line and failure statement if it does not find it (for each line). I want it to either print success or failure statement once for the searching of the whole array. thanks
      I'm with you, in that case just set a flag if the element is found, then break out of the loop at once (no point in continuing to search):
      my $found = 0; foreach (@commands_run){ if($_ =~ m/clock/) { $found = 1; last; } } if ($found) { print "\n Test -- found pattern -- \n" } else { print "\n Test -- did not find pattern -- \n" }

      maybe somthing like

      if(index("@commands_run",'clock') >= 0) { # string 'clock' found somewhere in array }

      -- 
      Ronald Fischer <ynnor@mm.st>