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.
In reply to Getting length of longest value in a column by Qukz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |