hotshot has asked for the wisdom of the Perl Monks concerning the following question:
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:
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:
Thanks
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:
parseColor() parses color control chars in the printed string, trancateStr() trancates a long string according to the given size.# 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) || ''; }
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:
Is there a better way?Path | Name | Description ------------------------------------------------------------------ | | /exadmin | testing | lalala / | test | /test1 | test1 (inactive) | hello RED - Directory is not accessible
Thanks
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Drawing a table
by blazar (Canon) on Jun 29, 2005 at 09:20 UTC | |
Re: Drawing a table
by marto (Cardinal) on Jun 29, 2005 at 09:22 UTC | |
Re: Drawing a table
by tomhukins (Curate) on Jun 29, 2005 at 09:41 UTC | |
Re: Drawing a table
by aukjan (Friar) on Jun 29, 2005 at 09:51 UTC | |
Re: Drawing a table
by fmerges (Chaplain) on Jun 29, 2005 at 09:34 UTC | |
Re: Drawing a table
by japhy (Canon) on Jun 29, 2005 at 12:08 UTC | |
by hotshot (Prior) on Jun 29, 2005 at 12:40 UTC | |
Re: Drawing a table
by Fletch (Bishop) on Jun 29, 2005 at 13:33 UTC |
Back to
Seekers of Perl Wisdom