JP wrote:
> The object of the code below is to output a list of space seperated
> fields with PID, username and process. The code generates te correct
> output. My guess is that my perl code can be smaller. Who dares?

unpack() with 'A' is handy for extracting and removing trailing blanks in
one step.

  for (grep /\S/, `tasklist /v /nh`) {
      chomp;
      my ($proc, $pid, $user, $title) = unpack 'A24 A8 x56 A50 x14 A*', $_;
      $proc = "$proc $title" unless $title eq 'N/A';
      $proc =~ s/ +/ /g;      # compress multiple spaces
      $pid += 0;              # convert to number
      $user =~ tr/ /_/;       # change blanks to underscores
      print join("\t", $pid, $user, $proc), "\n";
  }

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to