peschkaj has asked for the wisdom of the Perl Monks concerning the following question:
Regular expressions confuse me. Deeply.
I am grabbing a process name with Proc::ProcessTable, but I also need to grab out certain fields to display. I know that my current regular expression is horribly flawed, but I will provide what I am working with.
I am eventually going to use this code with SOAP so that I do not need to be on the UNIX box to view running processes. However, the process information often looks like this:
OPSms -N op01Sms1 -t SMS -T 0x70000000 -U op01/op011 -I sms1I need to grab the OPSms, op01Sms1, and 0x70000000 fields.
My "code":
#!/usr/bin/perl -w use strict; use Proc::ProcessTable; my $t = new Proc::ProcessTable; print "PID PPID UP START CMD TYPE CM +D NAME TRACE\n"; foreach my $p (@{$t->table}) { if ($p->{cmd} =~ /(op01)/) { my $seconds = $p->{time} % 60; my $diff = ($p->{time} - $seconds) / 60; my $minutes = $diff % 60; $seconds = "0$seconds" if $seconds =~ /^\d$/; my $bigTime = "$minutes:$seconds"; ### Grab process name, type, and trace from cmd $p->{cmd} =~ /(\w+)\b\w+\b(\w+?)\b/; my $procType = $1; my $procName = $2; #not checking for trace yet, since I can't get the procname my $FORMAT = "%-6s %-6s %-7s %-24s %-15s\n"; printf($FORMAT, $p->{pid}, $p->{ppid}, $bigTime, scalar(localtime($p->{start})), $procType, $procName); } }
I'm getting a "Use of unitialized value in printf at ./procs2.pl line 29" which is the printf.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex confusion
by Enlil (Parson) on Oct 30, 2002 at 17:38 UTC | |
|
Re: Regex confusion
by sauoq (Abbot) on Oct 30, 2002 at 19:06 UTC | |
|
Re: Regex confusion
by fglock (Vicar) on Oct 30, 2002 at 17:25 UTC | |
|
Re: Regex confusion
by peschkaj (Pilgrim) on Oct 30, 2002 at 17:46 UTC | |
|
Re: Regex confusion
by fglock (Vicar) on Oct 30, 2002 at 21:18 UTC | |
by peschkaj (Pilgrim) on Oct 31, 2002 at 03:37 UTC |