in reply to parsing variable input (perlre problem)
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 | |
by Moron (Curate) on Mar 19, 2007 at 16:59 UTC |