Block Confusion



Perlers,

I'm struggling; I'm using WMI to monitor a few processes (kinda like my
last disk monitor) but my output repeats the first process in a list for
as many items as I have in the list. See below:

use warnings;
use strict;

use Win32::OLE('in');

my $megaBytes = "1048576";

my $serverObj =
Win32::OLE->GetObject('winmgmts:{impersonationLevel=impersonate}')
or die "Unable to create server object: " . Win32::OLE->LastError()
.. "\n";

# list the processes to hunt for
my @findProcesses = (
"putty",
"firefox",
);

foreach my $process (in
$serverObj->InstancesOf("Win32_PerfFormattedData_PerfProc_Process")) {
foreach my $matchProcess ( @findProcesses ) {
if ( $process->{Name} =~ /$matchProcess/oi ) {

print "\n+----------+\nProcess Name: \t\t" . $process->{Name} .
"\n";
print "PID: \t\t\t" . $process->{IDProcess} . "\n";
print "PercentProcessorTime: \t" .
$process->{PercentProcessorTime} . "%\n";
print "PercentUserTime: \t" . $process->{PercentUserTime} . "%\n";
printf "WorkingSet: \t\t%4.2f MB\n", $process->{WorkingSet} /
$megaBytes;
printf "WorkingSetPeak: \t%4.2f MB\n", $process->{WorkingSetPeak}
/ $megaBytes;
printf "VirtualBytes: \t\t%4.2f MB\n", $process->{VirtualBytes} /
$megaBytes;
printf "VirtualBytesPeak: \t%4.2f MB\n",
$process->{VirtualBytesPeak} / $megaBytes;
}
}
}

This yields:

+----------+
Process Name: PUTTY
PID: 3244
PercentProcessorTime: 0%
PercentUserTime: 0%
WorkingSet: 1.24 MB
WorkingSetPeak: 4.00 MB
VirtualBytes: 30.52 MB
VirtualBytesPeak: 32.05 MB

+----------+
Process Name: PUTTY
PID: 3244
PercentProcessorTime: 0%
PercentUserTime: 0%
WorkingSet: 1.24 MB
WorkingSetPeak: 4.00 MB
VirtualBytes: 30.52 MB
VirtualBytesPeak: 32.05 MB

Instead of a line for each process in @findProcesses. I've tried
placing the line "foreach my $matchProcess ( @findProcesses) {" above
the first 'foreach', using a next statement instead of 'if', and placing
the print statements in a subroutine to be called (i.e.
getInfo($matchProcess)), not in any particular order, but the output is
always the same. I've even tried labeling the first block and called
next LABEL to no avail.

What am I missing/doing wrong? I swear I've been through this same
problem before on a previous script but I can't wrap my mind around
it...

ry
.