note
arturo
In a way, your code is doing exactly what you say you want it to: it is indeed matching every line in <code>@netstat</code> that matches [your] <code>@matches</code> 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 <code>netstat</code> output that matches *your entire <code>@matches</code> array*, interpreting that array as a string. The matching operator is a double-quote context (just like <code>print "@matches"</code>). And, as it says in [perldata]:
<code>
Arrays and slices are interpolated into double-quoted
strings by joining the elements with the delimiter
specified in the $" variable($LIST_SEPARATOR if
"use English;" is specified), space by default.
</code>
In other words, the line:
<code>
my @results = grep( /@matches/, @netstat );
</code>
comes out (given the rest of your code) as equivalent to
<code>my @results = grep(/invalid headers packets dropped/, @netstat);
</code>
in other words it's trying to find that whole "phrase." <p>I think you also mixed up your <code>foreach</code> loop, which loops over <code>@netstat</code>, when I think what you wanted was to check each element in <code>@matches</code>; putting all that together, I think your loop should be:
<code>
foreach my $match (@matches) {
my @results = grep /$match/, @results;
print @results;
}
</code>
</p>
<p>HTH</p>
<div class="pmsig">
<div class="pmsig-23317">
<p class="mysig">If not P, what? Q maybe? <br />"Sidney Morgenbesser"</p>
</div></div>
357410
357410