| 1 | package App::SimpleBackuper; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | sub _print_table { | ||
| 7 | my($table, $header_rows_cnt) = @_; | ||
| 8 | |||
| 9 | my @column_lengths = (0) x @{ $table->[0] }; | ||
| 10 | foreach my $row ( @$table ) { | ||
| 11 | $column_lengths[ $_ ] = length $row->[ $_ ] foreach grep { ! $column_lengths[ $_ ] or $column_lengths[ $_ ] < length $row->[ $_ ] } 0 .. $#$row; | ||
| 12 | } | ||
| 13 | |||
| 14 | for my $q ( 0 .. $#$table ) { | ||
| 15 | if($header_rows_cnt and $header_rows_cnt == $q) { | ||
| 16 | print '-' x ($column_lengths[ $_ ] + ($_ ? length(' | ') : 0)) foreach 0 .. $#{ $table->[$q] }; | ||
| 17 | print "\n"; | ||
| 18 | } | ||
| 19 | for my $w ( 0 .. $#{ $table->[ $q ] } ) { | ||
| 20 | printf "%-$column_lengths[ $w ]s", $table->[ $q ]->[ $w ]; | ||
| 21 | print $w == $#{ $table->[ $q ] } ? "\n" : ' | '; | ||
| 22 | } | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | 1; |