Hi all,
I have a command line interface Perl application which I'm running on a Linux machine. I want to create a command that display it's output in table format. is there a Perl module that can help me with that. Currently I'm drawing my table as follows:
# print table header
# fields space allocation: underline, Path, Name, status, desc, reset
+underline
printf "\n\t%s%-20s| %-10s%-12s| %-20s%s\n", &colorParse('%u'), 'Path'
+, 'Name', '', 'Description', &colorParse('%n'); # header with some c
+olor characters
printf "\t%-20s| %-10s%-12s| %-20s\n", '', '', '', ''; # empty line u
+nder the header
while (my($key, $val) = each(%{$shares})) {
.... # extract $path, $name, $status, $desc
# color constants should be assigned with separate space in printf
+ (their space is deducted when we print)
# fields space allocation: pathColor, path, pathReset, shareName,
+statusColor, status, statusReset, desc
printf "\t%s%-20s%s| %-10s%s%-12s%s| %-20s\n", $pathColor, &trunca
+teStr($path, 20), $pathReset, &truncateStr($name, 10), $statusColor,
+$status, $statusReset, &truncateStr($desc, 20) || '';
}
parseColor() parses color control chars in the printed string,
trancateStr() trancates a long string according to the given size.
This works fine most of the times, but as you can see it's quite clumzy and hard to maintain. The output looks something like this:
Path | Name | Description
------------------------------------------------------------------
| |
/exadmin | testing | lalala
/ | test |
/test1 | test1 (inactive) | hello
RED - Directory is not accessible
Is there a better way?
Thanks
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.