|Perl: the Markov chain saw|
Re: Trouble with foreach loop.... I thinkby arturo (Vicar)
|on May 29, 2004 at 03:53 UTC||Need Help??|
In a way, your code is doing exactly what you say you want it to: it is indeed matching every line in @netstat that matches [your] @matches list", but the way perl interprets that probably doesn't capture what you're thinking, What your code does is give you every line in the netstat output that matches *your entire @matches array*, interpreting that array as a string. The matching operator is a double-quote context (just like print "@matches"). And, as it says in perldata:
In other words, the line:
comes out (given the rest of your code) as equivalent to my @results = grep(/invalid headers packets dropped/, @netstat);
in other words it's trying to find that whole "phrase."
I think you also mixed up your foreach loop, which loops over @netstat, when I think what you wanted was to check each element in @matches; putting all that together, I think your loop should be:
If not P, what? Q maybe?