Qukz has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I'm trying to run a query and then from the results get the length of the longest value in a particular column and then use that number to pad the other columns so that all columns are equal widths... I know there are other ways to do this, but I'm (obviously) new and I'd like to know how to do it without any additional modules.
I've tried quite a few things (which have all failed for one reason or another), so to save space/everyone's time I'll just include the working code of the query:
use strict; use warnings; my $sth = $dbh->prepare($query); $sth->execute(); my ($TICKET_ID,$PRIORITY,$ABSTRACT); $sth->bind_columns(\($TICKET_ID,$ABSTRACT,$PRIORITY)); while (my $row = $sth->fetchrow_arrayref) { print "$TICKET_ID $ABSTRACT $PRIORITY \n"; }
So this returns something like:
TICKET123 Server unpingable Medium TICKET234 RPDU Audit Medium TICKET345 Network down High Ticket456 Check serial number Low Ticket567 Critical server unpingable High
So I'd like to get the length of the longest abstract, then pad the others so they're all the same width, making it look more like:
TICKET123 Server unpingable Medium TICKET234 RPDU audit Medium TICKET345 Network down High Ticket456 Check serial number Low Ticket567 Critical server unpingable High
Any help is greatly appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getting length of longest value in a column
by BrowserUk (Patriarch) on Feb 20, 2012 at 19:44 UTC | |
by GrandFather (Saint) on Feb 20, 2012 at 20:52 UTC | |
|
Re: Getting length of longest value in a column
by JavaFan (Canon) on Feb 20, 2012 at 18:49 UTC | |
|
Re: Getting length of longest value in a column
by repellent (Priest) on Feb 21, 2012 at 04:05 UTC | |
|
Re: Getting length of longest value in a column
by cursion (Pilgrim) on Feb 20, 2012 at 19:27 UTC | |
|
Re: Getting length of longest value in a column
by choroba (Cardinal) on Feb 21, 2012 at 11:14 UTC | |
|
Re: Getting length of longest value in a column
by Marshall (Canon) on Feb 22, 2012 at 03:20 UTC | |
|
Re: Getting length of longest value in a column
by sriharsha.sm (Initiate) on Feb 21, 2012 at 13:40 UTC |