Background: I am writing a subroutine which will be given a bunch of process descriptions like
"cmdline=/usr/bin/apache" or
"cmdline=/usr/bin/emacs /etc/passwd" or
"rss>123456". (Probably packaged in a hash).
It should use Proc::ProcessTable to look at each process in turn, and return all the data it has on the processes that match each description.
The problem is, Proc:ProcessTable returns an object, where every property of a process is an accessor method for that object.
Obviously, I can't do $p->$key==$val, much as that would come in handy right now.
I think that I need to either do something ugly with eval,
or create a chain of ifs like if ($key eq 'cmdline') {$match=$p->cmdline} elsif ($key eq... etc.
The matter is made more complicated because I have to return data about the process in a hash - I'm not allowed to just return a Proc::ProcessTable::Process object. That means that even if I use a series of ifs in the matching part, I still need a solution for the reporting part.
I was thinking of dispensing with Proc::ProcessTable altogether and just parsing the output of ps, but this code needs to run as transparently as possible on at least Linux and Solaris...
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.