in reply to Win32... CPU/RAM usage

Rather than going through all of the keys and testing for what you want perhaps you could just access those you want directly. Not tested as I use *nix mostly.

my @wantedInfoTypes = qw{ Name WorkingSetSize UserModeTime KernelModeTime}; ... for my $infoType ( @wantedInfoTypes ) { print qq{\n$infoType => \n}, q{-} x length $infoType, qq{\n$info->{$infoType}\n}; } ...

I hope this is of use.

Cheers,

JohnGG

Update: NetWallah's output shows that I missed a newline in the print statement which I've now corrected :)

Replies are listed 'Best First'.
Re^2: Win32... CPU/RAM usage
by mikejones (Scribe) on Jul 05, 2007 at 20:09 UTC
    I see your point, however I do want the flexibility in getting all information for all PIDS, but also want the ability to grab certain strings on demand. So my question still remains open for help! I liked you print block and will use that!
      One way to keep that flexibility would be to use something like Getopt::Long so that you could specify multiple items of interest on the command line which would populate an array. (Best to have a look at the documentation for Getopt::Long as I don't have an example to hand.) Then from the array create a compiled regular expression using the pipe symbol for alternation to use in the grep. If you didn't specify anything on the command line the array would be empty so in that case push (or unshift a . (dot) onto the array so the regex would match anything.

      use strict; use warnings; use Getopt::Long; my @wanted = (); GetOptions(q{want=s}, \@wanted); push @wanted, q{.} unless @wanted; my $rxWanted; { local $" = q{|}; $rxWanted = qr{@wanted}; } ... for my $key ( grep { m{$rxWanted} } keys %$info } { ... }

      Again, not tested but I think the concept is sound.

      Cheers,

      JohnGG