curtisb has asked for the wisdom of the Perl Monks concerning the following question:

Could someone please point me into the right direction. I seem to be blind this whole thing. I have looked all over the place including the perl books for a solution or an example. But I cannot find anything. Could someone point me in the right direction.
#/usr/bin/perl -w use Win32::IProcess; $process = new Win32::IProcess || die "Unable to create new process!: +$!\n"; $process -> EnumProcesses(\@processlist) || die "Unable to get process + list: $!\n"; foreach $process(@processlist){ $pid = $process ->{ProcessId}; $name = $process->{ProcessName}; $count = 0; while($count < $process(@processlist)){ $count++; } format STDOUT_TOP = Number Process Name Process Id ====== =================== ============= . format STDOUT = @<<<< @<<<<<<<<<<<<<<<<<<< @<<<< $count, $name, $pid . write; }

Any help would be greatly appreciated.
Curtisb

Replies are listed 'Best First'.
Re: While count ---don't see it
by Zaxo (Archbishop) on Mar 29, 2002 at 21:43 UTC

    This:

    foreach $process(@processlist){
    is clobbering this $process:
    $process = new Win32::IProcess || die "Unable to create new process!: +$!\n";
    One more case for $_, which means Thisun.
    for (@processlist){ $pid = $_ ->{ProcessId}; #...
    use strict; would not have prevented this, but you would be more likely to pay attention to scope.

    You don't need to redefine your formats every time through the loop.

    After Compline,
    Zaxo

Re: While count ---don't see it
by dws (Chancellor) on Mar 29, 2002 at 20:53 UTC
    What, exactly, do you expect
    while($count < $process(@processlist)){ $count++; }
    to do for you? Specifically, what do you think   $process(@processlist) evaluates to?

      Well, thanks, figured that out.
      while($count < @processlist){ $count++ }

      But, now my count is set to the number of the last process. It doesn't start at 0, even though I have it set in $count = 0;
      Any clues?
      curtisb
        Try
        while($count < $#processlist){ $count++ }


        "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
Re: While count ---don't see it
by curtisb (Monk) on Apr 01, 2002 at 16:31 UTC
    Everyone
    I appreciate the help. After taking all of your view in, I fixed my problem. I didn't need the while statement, because the foreach statement acts as the while. Plus, I had the write statement in the wrong place. I have provided the code below for everyone.
    #/usr/bin/perl -w use Win32::IProcess; $process = new Win32::IProcess || die "Unable to create new process!: +$!\n"; $process -> EnumProcesses(\@processlist) || die "Unable to get process + list: $!\n"; $count = 0; foreach (@processlist){ $pid = $_ ->{ProcessId}; $name = $_ ->{ProcessName}; $count++; write; } format STDOUT_TOP = Number Process Name Process Id ====== =================== ============= . format STDOUT = @<<<< @<<<<<<<<<<<<<<<<<<< @<<<< $count, $name, $pid .
    Plus, if anyone would like to find the Win32::IProcess modules you can map your PPM repository to this URL.
    http://idnopheq.perlmonk.org/perl/packages
    So, I thank all of the monks for all of the help.
    Thanks,
    Curtisb