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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.