This should help you find a less chaotic direction. The code is not complete and some bits are not along your wish, but the code is plastic.
You need to improve the value transformation and commation-commification function (
rc in the code). 1024 MB is 1073741824 bytes (1024 ** 3), not 1024 * 1000 * 1000.
As for the comma or commas, there might be such a printf option. I'm not sure, but wouldn't be surprised.
This function will also integrate nicely with translation to other measure bases (GB or whatever).
sub rc {
my $n = int shift()/1024;
$n =~ s/(\d+?)(\d{3})$/$1,$2/;
return $n;
}
s/([^:]+:)\s+(\d+)\s+KB/
sprintf "%-14s%10s MB", $1, rc($2)/e;
s/^\=+$/"=" x 68/e;
my $IMCfmt = "%-17s%17s%17s%17s";
s/^(Name)\s+(Mem Used)\s+\(KB\)\s+(HWM Used)\s+\(KB\)\s+(Cached)\s+\(K
+B\)/
sprintf $IMCfmt, $1, $2." (MB)", $3." (MB)", $4." (MB)"/e;
s/^([APPL-|DBMS-|FMP_|PRIVATE|DB-]\S*)\s+(\d+)\s+(\d+)\s+(\d+)/
sprintf $IMCfmt, $1, rc($2), rc($3), rc($4)/e;
I FORGOT: I used the -p switch on the command line instead of the -n. (That's where all the prints are.)
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.