line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!perl
|
2
|
|
|
|
|
|
|
#
|
3
|
|
|
|
|
|
|
# Documentation, copyright and license is at the end of this file.
|
4
|
|
|
|
|
|
|
#
|
5
|
|
|
|
|
|
|
package Text::Column;
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4494
|
use 5.001;
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
47
|
|
8
|
1
|
|
|
1
|
|
6
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
9
|
1
|
|
|
1
|
|
22
|
use warnings;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
24
|
|
10
|
1
|
|
|
1
|
|
5
|
use warnings::register;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
149
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION $DATE $FILE);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
92
|
|
13
|
|
|
|
|
|
|
$VERSION = '1.11';
|
14
|
|
|
|
|
|
|
$DATE = '2004/04/29';
|
15
|
|
|
|
|
|
|
$FILE = __FILE__;
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
6
|
use vars qw(@ISA @EXPORT_OK);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1146
|
|
18
|
|
|
|
|
|
|
require Exporter;
|
19
|
|
|
|
|
|
|
@ISA= qw(Exporter);
|
20
|
|
|
|
|
|
|
@EXPORT_OK = qw(format_hash_table format_array_table);
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
######
|
23
|
|
|
|
|
|
|
# Format hash table
|
24
|
|
|
|
|
|
|
#
|
25
|
|
|
|
|
|
|
sub format_hash_table
|
26
|
|
|
|
|
|
|
{
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
######
|
29
|
|
|
|
|
|
|
# This subroutine uses no object data; therefore,
|
30
|
|
|
|
|
|
|
# drop any class or object.
|
31
|
|
|
|
|
|
|
#
|
32
|
2
|
50
|
|
2
|
1
|
13
|
shift @_ if UNIVERSAL::isa($_[0],__PACKAGE__);
|
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
|
|
5
|
my ($h_p, $width_p, $header_p) = @_;
|
35
|
|
|
|
|
|
|
|
36
|
2
|
50
|
|
|
|
6
|
unless (ref($h_p) eq 'HASH') {
|
37
|
0
|
|
|
|
|
0
|
warn "# Table to format must be an hash table\n";
|
38
|
0
|
|
|
|
|
0
|
return undef;
|
39
|
|
|
|
|
|
|
}
|
40
|
|
|
|
|
|
|
|
41
|
2
|
|
|
|
|
4
|
my @array_table = ();
|
42
|
2
|
|
|
|
|
2
|
my (@key_stack, @keys, $key, $entries_p, @entries, $entry);
|
43
|
2
|
|
|
|
|
13
|
@keys = sort keys %$h_p;
|
44
|
2
|
|
|
|
|
8
|
while( @keys ) {
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#######
|
47
|
|
|
|
|
|
|
# Using the @array_column pre-fix from the previous interrupted
|
48
|
|
|
|
|
|
|
# hash column
|
49
|
|
|
|
|
|
|
#
|
50
|
|
|
|
|
|
|
# Since pushing pointers, instead of values, need to begin a
|
51
|
|
|
|
|
|
|
# a brand new @array_column
|
52
|
|
|
|
|
|
|
#
|
53
|
11
|
100
|
|
|
|
21
|
my @array_column = (@key_stack) ? @{$key_stack[-1]} : ();
|
|
5
|
|
|
|
|
9
|
|
54
|
11
|
|
|
|
|
20
|
$key = shift @keys;
|
55
|
11
|
|
|
|
|
17
|
push @array_column, $key;
|
56
|
11
|
|
|
|
|
14
|
$entries_p = $h_p->{$key};
|
57
|
11
|
100
|
|
|
|
25
|
if (ref($entries_p) eq 'ARRAY' ) {
|
58
|
3
|
|
|
|
|
6
|
push @array_column,@$entries_p;
|
59
|
3
|
|
|
|
|
5
|
push @array_table, \@array_column;
|
60
|
3
|
|
|
|
|
8
|
next;
|
61
|
|
|
|
|
|
|
}
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
#######
|
64
|
|
|
|
|
|
|
# Have a hash column. Remember where at for the
|
65
|
|
|
|
|
|
|
# current column and sort the keys for the next
|
66
|
|
|
|
|
|
|
# column.
|
67
|
|
|
|
|
|
|
#
|
68
|
8
|
100
|
|
|
|
17
|
if (ref($entries_p) eq 'HASH' ) {
|
69
|
3
|
|
|
|
|
6
|
my @keep_keys = @keys;
|
70
|
3
|
|
|
|
|
7
|
push @key_stack, (\@keep_keys, $h_p, \@array_column);
|
71
|
3
|
|
|
|
|
4
|
$h_p = $entries_p;
|
72
|
3
|
|
|
|
|
11
|
@keys = sort keys %$h_p;
|
73
|
3
|
|
|
|
|
8
|
next;
|
74
|
|
|
|
|
|
|
}
|
75
|
|
|
|
|
|
|
|
76
|
5
|
|
|
|
|
7
|
push @array_table, \@array_column;
|
77
|
5
|
100
|
|
|
|
14
|
unless(@keys) {
|
78
|
3
|
|
|
|
|
4
|
pop @key_stack;
|
79
|
3
|
|
|
|
|
4
|
$h_p = pop @key_stack;
|
80
|
3
|
|
|
|
|
5
|
@keys = @{pop @key_stack};
|
|
3
|
|
|
|
|
10
|
|
81
|
|
|
|
|
|
|
}
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
}
|
84
|
|
|
|
|
|
|
|
85
|
2
|
|
|
|
|
7
|
Text::Column->format_array_table( \@array_table, $width_p, $header_p );
|
86
|
|
|
|
|
|
|
}
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
######
|
90
|
|
|
|
|
|
|
# Format an array table.
|
91
|
|
|
|
|
|
|
#
|
92
|
|
|
|
|
|
|
sub format_array_table
|
93
|
|
|
|
|
|
|
{
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
######
|
96
|
|
|
|
|
|
|
# This subroutine uses no object data; therefore,
|
97
|
|
|
|
|
|
|
# drop any class or object.
|
98
|
|
|
|
|
|
|
#
|
99
|
3
|
50
|
|
3
|
1
|
685
|
shift @_ if UNIVERSAL::isa($_[0],__PACKAGE__);
|
100
|
|
|
|
|
|
|
|
101
|
3
|
|
|
|
|
5
|
my ($a_p, $width_p, $header_p) = @_;
|
102
|
|
|
|
|
|
|
|
103
|
3
|
50
|
|
|
|
10
|
unless (ref($a_p) eq 'ARRAY') {
|
104
|
0
|
|
|
|
|
0
|
warn "# Table to format must be an array table\n";
|
105
|
0
|
|
|
|
|
0
|
return undef;
|
106
|
|
|
|
|
|
|
}
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
######
|
109
|
|
|
|
|
|
|
# Format the inventory list
|
110
|
|
|
|
|
|
|
#
|
111
|
3
|
50
|
|
|
|
7
|
unless (ref($width_p) eq 'ARRAY') {
|
112
|
0
|
|
|
|
|
0
|
warn "# Width must be an array\n";
|
113
|
0
|
|
|
|
|
0
|
return undef;
|
114
|
|
|
|
|
|
|
}
|
115
|
3
|
|
|
|
|
9
|
my @w = @$width_p;
|
116
|
3
|
|
|
|
|
4
|
my $total=0;
|
117
|
3
|
|
|
|
|
3
|
my (@dash, @header);
|
118
|
3
|
|
|
|
|
4
|
foreach my $w (@w) {
|
119
|
10
|
|
|
|
|
12
|
$total += $w;
|
120
|
10
|
|
|
|
|
25
|
push @dash,'-' x $w;
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
}
|
123
|
3
|
|
|
|
|
12
|
unshift @$a_p,[@dash];
|
124
|
3
|
|
|
|
|
7
|
unshift @$a_p,[@$header_p];
|
125
|
|
|
|
|
|
|
|
126
|
3
|
|
|
|
|
3
|
my ($type, $r_p, @r, $r, $r_total, $c, $size);
|
127
|
3
|
|
|
|
|
5
|
my $str = "\n ";
|
128
|
3
|
|
|
|
|
6
|
foreach $r_p (@$a_p) {
|
129
|
|
|
|
|
|
|
|
130
|
17
|
50
|
|
|
|
37
|
unless (ref($r_p) eq 'ARRAY') {
|
131
|
0
|
|
|
|
|
0
|
warn "# Rows in table to format must be an arrays\n";
|
132
|
0
|
|
|
|
|
0
|
return undef;
|
133
|
|
|
|
|
|
|
}
|
134
|
|
|
|
|
|
|
|
135
|
17
|
|
|
|
|
39
|
@r = @$r_p;
|
136
|
|
|
|
|
|
|
|
137
|
17
|
|
|
|
|
23
|
$r_total = 0;
|
138
|
17
|
|
|
|
|
23
|
foreach $r (@r) {
|
139
|
54
|
|
|
|
|
74
|
$r_total += length( $r);
|
140
|
|
|
|
|
|
|
}
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
#####
|
143
|
|
|
|
|
|
|
# Mutlitple of single line
|
144
|
|
|
|
|
|
|
#
|
145
|
17
|
50
|
|
|
|
33
|
$type = ($total < $r_total) ? 1 :0;
|
146
|
17
|
50
|
|
|
|
33
|
if ($type) {
|
147
|
0
|
|
|
|
|
0
|
$str =~ s/(.*?)\s*$/$1/sg; # drop trailing white space
|
148
|
0
|
|
|
|
|
0
|
$str .= "\n ";
|
149
|
|
|
|
|
|
|
}
|
150
|
|
|
|
|
|
|
|
151
|
17
|
|
|
|
|
33
|
while( $r_total ) {
|
152
|
17
|
|
|
|
|
36
|
for( $c=0; $c < @w; $c++ ) {
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
#######
|
155
|
|
|
|
|
|
|
# Determine amount of row entry to use for column
|
156
|
|
|
|
|
|
|
#
|
157
|
54
|
|
|
|
|
60
|
$size = length( $r[$c] );
|
158
|
54
|
50
|
|
|
|
83
|
$size = ($w[$c] < $size) ? $w[$c] : $size;
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
########
|
161
|
|
|
|
|
|
|
# Add row to column
|
162
|
|
|
|
|
|
|
#
|
163
|
54
|
|
|
|
|
84
|
$str .= substr( $r[$c], 0, $size );
|
164
|
54
|
50
|
|
|
|
88
|
if ($size < length( $r[$c] )) {
|
165
|
0
|
|
|
|
|
0
|
$r[$c] = substr( $r[$c], $size);
|
166
|
|
|
|
|
|
|
}
|
167
|
|
|
|
|
|
|
else {
|
168
|
54
|
|
|
|
|
72
|
$r[$c] = '';
|
169
|
54
|
|
|
|
|
86
|
$str .= ' ' x ($w[$c] - $size);
|
170
|
|
|
|
|
|
|
}
|
171
|
54
|
100
|
|
|
|
84
|
if($c < (@w - 1)) {
|
172
|
37
|
|
|
|
|
124
|
$str .= ' ';
|
173
|
|
|
|
|
|
|
}
|
174
|
|
|
|
|
|
|
else {
|
175
|
17
|
|
|
|
|
394
|
$str =~ s/(.*?)\s*$/$1/sg; # drop trailing white space
|
176
|
17
|
|
|
|
|
53
|
$str .= "\n ";
|
177
|
|
|
|
|
|
|
}
|
178
|
|
|
|
|
|
|
}
|
179
|
|
|
|
|
|
|
|
180
|
17
|
50
|
|
|
|
44
|
$r[$c] = '' unless($c < @w); # ran out of columns
|
181
|
|
|
|
|
|
|
|
182
|
17
|
|
|
|
|
19
|
$r_total = 0;
|
183
|
17
|
|
|
|
|
22
|
foreach $r (@r) {
|
184
|
71
|
|
|
|
|
114
|
$r_total = length( $r);
|
185
|
|
|
|
|
|
|
}
|
186
|
|
|
|
|
|
|
}
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
17
|
50
|
|
|
|
36
|
if ($type) {
|
190
|
0
|
|
|
|
|
0
|
$str =~ s/(.*?)\s*$/$1/sg; # drop trailing white space
|
191
|
0
|
|
|
|
|
0
|
$str .= "\n ";
|
192
|
|
|
|
|
|
|
}
|
193
|
|
|
|
|
|
|
}
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
######
|
196
|
|
|
|
|
|
|
# Clean up table
|
197
|
|
|
|
|
|
|
#
|
198
|
3
|
|
|
|
|
18
|
$str =~ s/^\s*(.*)\n\s*$/$1/s; # drop leading trailing white space
|
199
|
3
|
|
|
|
|
10
|
while( chomp $str ) { }; # single line feed at the end
|
200
|
3
|
|
|
|
|
3
|
$str .= "\n";
|
201
|
3
|
|
|
|
|
27
|
$str = ' ' . $str;
|
202
|
|
|
|
|
|
|
}
|
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
1
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
__END__
|