Cool! I'm down to 161 bytes now, short enough for a oneliner at the C:\>
prompt.

for(grep/\S/,`tasklist /v /nh`){
chomp;my($p,$i,$u,$t)=unpack'A24A8x56A50x14A*',$_;$p="$p $t"unless$t
eq'N/A';$p=~s/ +/ /g;$i+=0;$u=~tr/ /_/;print"$i $u $p\n"}

Don't worry guys, my other scripts are far more readable :-)

JP


"Bob Showalter" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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