1
2
3
4
5
6
7
8
9
10
11
use Term::TablePrint qw(print_table);
my $table = [
[ 1, 'Ruth' ],
[ 2, 'John' ],
[ 3, 'Mark' ],
[ 4, 'Nena' ]
];
print_table( $table, { add_header => 1 } );
1
2
3
if ( $self->{add_header} ) {
unshift @$table_ref, [ map { $_ . 'col' } 1 .. @{$table_ref->[0]} ];
}
1
2
3
4
5
6
7
8
9
10
11
if ( @{$self->{col_names}} ) {
my $missing = @{$table_ref->[0]} - @{$self->{col_names}};
if ( $missing > 0 ) {
my $last = pop @{$self->{col_names}};
unshift @$table_ref, [ @{$self->{col_names}}, map { $_ . $last } 1 .. $missing + 1 ];
push @{$self->{col_names}}, $last;
}
else {
unshift @$table_ref, [ @{$self->{col_names}}[ 0 .. $#{$table_ref->[0]} ] ];
}
}
print_table( $table, { col_names => [1, 2, 3, 4, 5] } );