Sudarsan Raghavan wrote:

> -------- Original Message --------
> Subject: Re: Help with parsing output
> Date: Fri, 31 May 2002 11:07:16 +0530
> From: Sudarsan Raghavan <[EMAIL PROTECTED]>
> Organization: HP ISO
> To: "John W. Krahn" <[EMAIL PROTECTED]>
> References: <[EMAIL PROTECTED]>
> <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
>
> "John W. Krahn" wrote:
>
> > Sudarsan Raghavan wrote:
> > >
> > > "Kipp, James" wrote:
> > >
> > > > I am reading output from a pipe to a command called 'prstat' (like top).
> > > > just wanted to get some ideas on the best way to capture the data i am
> > > > looking for. below is an example of the output:
> > >
> > > # INPUTDATA is the filehandle through which you are getting the input
> > > while (<INPUTDATA>) {
> > >     chomp;
> >
> > chomp() isn't really needed as the split on whitespace removes newlines
> > (\s includes \n).
> >
> > >     s/^\s+//;
> >
> > If you use the default split you won't need this either.
> >
> > >     next if (m/^$/ || (1 .. /^NPROC/));
> > >     unless (/^Total/) {
> > >         # Assumes the line to stop searching for input starts with Total
> > >         my ($user, $mem, $cpu) = (split (/\s+/))[1, 4, 6];
> >
> >         my ($user, $mem, $cpu) = (split)[1, 4, 6];
> >
> > >         print "user = $user, mem = $mem, cpu = $cpu\n";
> > >     }
> > > }
> > > close (INPUTDATA);
> >
> > How about something like this:   :-)
>
> Thanks for pointers :-)
>
> >
> >
> > while ( <INPUTDATA> ) {
> >     if ( /NPROC/ .. /^Total/ and /\d/ ) {
>
> I guess you meant /^NPROC/

No you did not, sorry :-)

>
>
> >
> >         my ( $user, $mem, $cpu ) = (split)[1, 4, 6];
> >         print "user = $user, mem = $mem, cpu = $cpu\n";
> >         }
> >     }
> >
> > John
> > --
> > use Perl;
> > program
> > fulfillment
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to