line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
|
|
|
|
|
|
package fmtcol; |
3
|
|
|
|
|
|
|
# ABSTRACT: Format lines of text as columns |
4
|
|
|
|
|
|
|
$fmtcol::VERSION = '0.007'; |
5
|
1
|
|
|
1
|
|
5906
|
use Pod::Usage qw( pod2usage ); |
|
1
|
|
|
|
|
64036
|
|
|
1
|
|
|
|
|
93
|
|
6
|
1
|
|
|
1
|
|
802
|
use Getopt::Long qw( GetOptionsFromArray ); |
|
1
|
|
|
|
|
8838
|
|
|
1
|
|
|
|
|
5
|
|
7
|
1
|
|
|
1
|
|
572
|
use Term::FormatColumns qw( format_columns format_columns_for_width ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub main { |
10
|
2
|
|
|
2
|
|
1291
|
my ( $class, @argv ) = @_; |
11
|
2
|
|
|
|
|
4
|
my %opt; |
12
|
2
|
|
|
|
|
7
|
GetOptionsFromArray( \@argv, \%opt, |
13
|
|
|
|
|
|
|
'width|w=i', |
14
|
|
|
|
|
|
|
'help|h', |
15
|
|
|
|
|
|
|
'version', |
16
|
|
|
|
|
|
|
); |
17
|
2
|
50
|
|
|
|
590
|
return pod2usage(0) if $opt{help}; |
18
|
2
|
50
|
|
|
|
6
|
if ( $opt{version} ) { |
19
|
0
|
|
|
|
|
0
|
print "fmtcol version $Term::FormatColumns::VERSION (Perl $^V)\n"; |
20
|
0
|
|
|
|
|
0
|
return 0; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
|
|
3
|
my @files = @argv; |
24
|
2
|
100
|
|
|
|
4
|
push @files, '-' if !@argv; |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
|
|
2
|
my @lines; |
27
|
2
|
|
|
|
|
3
|
for my $file ( @files ) { |
28
|
2
|
|
|
|
|
2
|
my $fh; |
29
|
2
|
100
|
|
|
|
4
|
if ( $file eq '-' ) { |
30
|
1
|
|
|
|
|
2
|
$fh = \*STDIN; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
else { |
33
|
1
|
50
|
|
|
|
39
|
open $fh, '<', $file or die "Could not open file '$file' for reading: $!\n"; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
17
|
while ( my $line = <$fh> ) { |
37
|
12
|
|
|
|
|
13
|
chomp $line; |
38
|
12
|
|
|
|
|
30
|
push @lines, $line; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
2
|
50
|
|
|
|
5
|
if ( $opt{width} ) { |
43
|
2
|
|
|
|
|
6
|
print format_columns_for_width( $opt{width}, @lines ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
else { |
46
|
0
|
|
|
|
|
0
|
print format_columns( @lines ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
7
|
return 0; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
exit __PACKAGE__->main( @ARGV ) unless caller(0); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |