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: :-) while ( <INPUTDATA> ) { if ( /NPROC/ .. /^Total/ and /\d/ ) { 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]