in reply to parsing variable input (perlre problem)

Assuming there is good reason not to use the module suggested earlier...

The thing that jumps out at me is the fact that ps output is fixed field format whereas the regexps are matching anywhere on the line of ps output. Therefore it is going to be easier and more reliable to extract fields using substr before then matching their contents against your expressions. For example:

my $flds = [{ name => UID, start => 0, length => 8 }, { name => PID, start => 8, length => 6 ), # etc. # matches the ps header line in this e.g. ]; my $pid = open my $ph, "ps -ef |" or die $!; my @hdr = split /\s+/, <$ph>; while( <$ph> ) { my %line; for my $fld ( @$flds ) { $line{ $fld -> { name } } = substr ( $_, $fld -> { start }, $f +ld -> { length } ); } # and then match $line{ STIME } against regexps. } waitpid $pid, 0; close $ph

-M

Free your mind

Replies are listed 'Best First'.
Re^2: parsing variable input (perlre problem)
by davorg (Chancellor) on Mar 19, 2007 at 16:50 UTC
      In that case just read the field positions and widths off the header -- if a field "goes wide", the header changes to match and the header is otherwise predictable even though some columns are aligned left, some right - still in a predictable way.

      -M

      Free your mind