#!/usr/bin/perl # (tested) use strict; use warnings; my @AoA = (); Insert( \@AoA, 'Planet', 'Radius', 'Density' ); Insert( \@AoA, 'Mercury', 2360, 3.7 ); Insert( \@AoA, 'Jupiter', 71030, 1.3 ); print Formit( \@AoA ); sub Formit { my $aoaref = shift; my $aref = $aoaref -> [0]; my $return = Line($aref); $return .= FormatLine($aref, 'CENTRE', 'CENTRE', 'CENTRE' ); $return .= Line($aref); shift @$aoaref; for $aref ( @$aoaref ) { $return .= FormatLine( $aref, 'LEFT', 'LM4', 'LM4' ); } $return .= Line( $aref ); return $return; } sub FormatLine{ my $aref = shift; my $return = '|'; for my $field ( @$aref ) { my $format = shift; my $formatted = ( ' ' x 12 ); my $pos = ( $format eq 'LEFT' ) ? 0 : ( $format eq 'CENTRE' ) ? 6 - (length( $field ) / 2 +) : ( $format =~ /^LM(\d+)/ ) ? $1 : 0; substr( $formatted, $pos, length( $field ) ) = $field; $return .= $formatted . '|'; } return $return . "\n"; } sub Line { my $aref = shift; my $cols = ( 13 * ( $#$aref + 1 ) ) + 1; return ( '-' x $cols ) . "\n"; } sub Insert{ my $aoaref = shift; my @a = @_; push @$aoaref, \@a; }
-M
Free your mind
In reply to Re: Printing Issues with Text::Table
by Moron
in thread Printing Issues with Text::Table
by neversaint
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |