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

Re: [FWP] grepps script...



On Sat, Jul 31, 1999 at 09:01:20PM -0400, Prakash Kailasa wrote:
> 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>;

Thanks for the latter half of this line, I need to read up on the
functions like map and grep, I think my code (not just this example)
is missing some flavor by my unfamiliarity with such expressions...
that piece of code has now been assimilated into my local copy :)

However, I have to ask, why did you set the input record separator in
the first half?  Isn't it newline by default?  I haven't changed it
anywhere in the script, so I fail to see why that assignment was made.
Am I missing something here?

Thanks,
Stevie

-- 
Eric Raymond:  I want to live in a world where software doesn't suck.
Richard Stallman:  Any software that isn't free sucks.
Linus Torvalds:  I'm interested in free beer.
Richard Stallman:  That's okay, as long as I don't have to drink it.  I
don't like beer.           -- LinuxWorld Expo panel, 4 March 1999

PGP signature