[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] grepps script...



Stevie Strickland wrote:

> This is a script I wrote to grep all the user's processes in the
> process table *without* returning any of the processes used to do
> it (unlike a simple `ps ax|grep foo`, which would randomly return
> the "grep foo" process)...
>
> #!/usr/bin/perl -w
> die "No search string given!\n" if !defined($ARGV[0]);
> $kpid = open(PS_X, "ps x|") or die "Can't open program: $!";
> while(<PS_X>) { print if (/$ARGV[0]/ && !/\s*(?:$$|$kpid)/); }

Make the last line:
  $/ = "\n"; print grep /$ARGV[0]/ && !/\s*(?:$$|$kpid)/, <PS_X>;

/prakash

> So, oh great masters of Perl obfuscation and compression, is there
> anything obvious that can be done with this to make it even smaller? :)
>
> Thanks,
> Stevie




==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe