| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package File::Utils; |
|
2
|
2
|
|
|
2
|
|
2593
|
use Modern::Perl; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
10
|
|
|
3
|
2
|
|
|
2
|
|
208
|
use Carp; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
89
|
|
|
4
|
2
|
|
|
2
|
|
752
|
use PerlIO::gzip; |
|
|
2
|
|
|
|
|
896
|
|
|
|
2
|
|
|
|
|
53
|
|
|
5
|
2
|
|
|
2
|
|
8
|
use Exporter; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
707
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.0.5'; # VERSION |
|
8
|
|
|
|
|
|
|
# ABSTRACT: Provide various of file operation |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = ('Exporter'); |
|
11
|
|
|
|
|
|
|
our @EXPORT = (); |
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw/read_handle write_handle file2array/; |
|
13
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
|
14
|
|
|
|
|
|
|
gz => [qw/read_handle write_handle/], |
|
15
|
|
|
|
|
|
|
data => [qw/file2array/] |
|
16
|
|
|
|
|
|
|
); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub read_handle { |
|
21
|
1
|
|
|
1
|
1
|
4437
|
my $file = shift; |
|
22
|
1
|
|
|
|
|
3
|
my $handle; |
|
23
|
1
|
50
|
|
|
|
13
|
if ($file =~/\.gz$/) { |
|
24
|
1
|
|
|
|
|
58
|
open $handle, "<:gzip", $file; |
|
25
|
|
|
|
|
|
|
} else { |
|
26
|
0
|
|
|
|
|
0
|
open $handle, "<", $file; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
1
|
|
|
|
|
19
|
$handle->autoflush; |
|
29
|
1
|
|
|
|
|
96
|
return $handle; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub write_handle { |
|
34
|
0
|
|
|
0
|
1
|
|
my $file = shift; |
|
35
|
0
|
|
|
|
|
|
my $handle; |
|
36
|
0
|
0
|
|
|
|
|
if ($file =~/\.gz$/) { |
|
37
|
0
|
|
|
|
|
|
open $handle, ">:gzip", $file; |
|
38
|
|
|
|
|
|
|
} else { |
|
39
|
0
|
|
|
|
|
|
open $handle, ">", $file; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
0
|
|
|
|
|
|
$handle->autoflush; |
|
42
|
0
|
|
|
|
|
|
return $handle; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub file2array { |
|
47
|
0
|
|
|
0
|
1
|
|
my ($filename, $sep) = @_; |
|
48
|
0
|
|
0
|
|
|
|
$sep ||= "\t"; |
|
49
|
0
|
|
|
|
|
|
open my $file, "<", "$filename"; |
|
50
|
0
|
|
|
|
|
|
my @out; |
|
51
|
0
|
|
|
|
|
|
while (my $line = <$file>) { |
|
52
|
0
|
|
|
|
|
|
chomp($line); |
|
53
|
0
|
|
|
|
|
|
my @cols = split $sep, $line; |
|
54
|
0
|
|
|
|
|
|
push @out, \@cols; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
0
|
|
|
|
|
|
close($file); |
|
57
|
0
|
|
|
|
|
|
return @out; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |