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 sms1

I 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.



If you make something idiot-proof, eventually someone will make a better idiot.
I am that better idiot.

In reply to Regex confusion by peschkaj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.