line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::ReadSimple; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6345
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
45
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
1564
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
our (@ISA, @EXPORT, $VERSION); |
11
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
@EXPORT = qw(file_read file_read_line file_bulk_read_line file_read_last_lines file_read_first_lines file_read_odd_lines file_read_even_lines file_grep_word file_grep_word_line_no file_tail file_word_replace ); |
13
|
|
|
|
|
|
|
$VERSION = "1.0"; |
14
|
|
|
|
|
|
|
# Preloaded methods go here. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub file_read { |
17
|
0
|
0
|
|
0
|
0
|
|
open ( FILEREAD, "@_" ) || die "File not found" ; |
18
|
0
|
|
|
|
|
|
while ( readline *FILEREAD ) |
19
|
|
|
|
|
|
|
{ |
20
|
0
|
|
|
|
|
|
print $_; |
21
|
|
|
|
|
|
|
} |
22
|
0
|
|
|
|
|
|
close ( FILEREAD ); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub file_read_line { |
26
|
0
|
|
|
0
|
0
|
|
my $linenumber = $_[1] -1; |
27
|
0
|
0
|
|
|
|
|
open ( FILEREADLINE, "$_[0]" ) || die "File not found" ; |
28
|
0
|
|
|
|
|
|
my @lines = ; |
29
|
0
|
|
|
|
|
|
print $lines[$linenumber]; |
30
|
0
|
|
|
|
|
|
close ( FILEREADLINE ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub file_bulk_read_line { |
34
|
0
|
|
|
0
|
0
|
|
my $linestart = $_[1] - 1; |
35
|
0
|
|
|
|
|
|
my $lineend = $_[2]; |
36
|
0
|
0
|
|
|
|
|
open ( FILEBULKREAD, "$_[0]" ) || die "File not found" ; |
37
|
0
|
|
|
|
|
|
my @line = ; |
38
|
0
|
|
|
|
|
|
while ( $linestart < $lineend ) |
39
|
|
|
|
|
|
|
{ |
40
|
0
|
|
|
|
|
|
print $line[$linestart]; |
41
|
0
|
|
|
|
|
|
$linestart = $linestart + 1; |
42
|
|
|
|
|
|
|
} |
43
|
0
|
|
|
|
|
|
close ( FILEBULKREAD ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub file_read_last_lines { |
47
|
0
|
|
|
0
|
0
|
|
my $linestart = $_[1]; |
48
|
0
|
0
|
|
|
|
|
open ( LASTLINES, "$_[0]" ) || die "File not found"; |
49
|
0
|
|
|
|
|
|
my @li = ; |
50
|
0
|
|
|
|
|
|
while ( $linestart > 0 ) |
51
|
|
|
|
|
|
|
{ |
52
|
0
|
|
|
|
|
|
print $li[-$linestart]; |
53
|
0
|
|
|
|
|
|
$linestart = $linestart - 1; |
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
|
close ( LASTLINES ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub file_read_first_lines { |
59
|
0
|
0
|
|
0
|
0
|
|
open ( FIRSTLINES, "$_[0]" ) || die "File not found"; |
60
|
0
|
|
|
|
|
|
my @li = ; |
61
|
0
|
|
|
|
|
|
my $line = 0; |
62
|
0
|
|
|
|
|
|
while ( $line < $_[1] ) |
63
|
|
|
|
|
|
|
{ |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
print $li[$line]; |
66
|
0
|
|
|
|
|
|
$line = $line + 1; |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
close ( FIRSTLINES ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub file_read_odd_lines { |
72
|
0
|
0
|
|
0
|
0
|
|
open ( ODD, $_[0]) || die "File not found"; |
73
|
0
|
|
|
|
|
|
my @data = ; |
74
|
0
|
|
|
|
|
|
my $i = "1"; |
75
|
0
|
|
|
|
|
|
my $size = $#data + 1; |
76
|
0
|
|
|
|
|
|
while ( $i <= $size ) |
77
|
|
|
|
|
|
|
{ |
78
|
0
|
|
|
|
|
|
print "$data[$i]"; |
79
|
0
|
|
|
|
|
|
$i = $i + 2; |
80
|
|
|
|
|
|
|
} |
81
|
0
|
|
|
|
|
|
close ( ODD ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub file_read_even_lines { |
85
|
0
|
0
|
|
0
|
0
|
|
open ( EVEN, "$_[0]" ) || die "File not found"; |
86
|
0
|
|
|
|
|
|
my @data = ; |
87
|
0
|
|
|
|
|
|
my $i = "0"; |
88
|
0
|
|
|
|
|
|
my $size = $#data + 1; |
89
|
0
|
|
|
|
|
|
while ( $i <= $size ) |
90
|
|
|
|
|
|
|
{ |
91
|
0
|
|
|
|
|
|
print "$data[$i]"; |
92
|
0
|
|
|
|
|
|
$i = $i + 2; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
0
|
|
|
|
|
|
close ( EVEN ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub file_grep_word { |
99
|
0
|
0
|
|
0
|
0
|
|
open ( FILEGREP, "$_[0]" ) || die "File not found" ; |
100
|
0
|
|
|
|
|
|
while ( readline *FILEGREP ) |
101
|
|
|
|
|
|
|
{ |
102
|
0
|
0
|
|
|
|
|
print $_ if ( $_ =~ /$_[1]/ ); |
103
|
|
|
|
|
|
|
} |
104
|
0
|
|
|
|
|
|
close ( FILEGREP ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub file_grep_word_line_no { |
108
|
0
|
|
|
0
|
0
|
|
my $no = "1"; |
109
|
0
|
0
|
|
|
|
|
open ( FILEGREPNO, "$_[0]" ) || die "File not found" ; |
110
|
0
|
|
|
|
|
|
while ( readline *FILEGREPNO ) |
111
|
|
|
|
|
|
|
{ |
112
|
|
|
|
|
|
|
|
113
|
0
|
0
|
|
|
|
|
print "$no:$_ " if ( $_ =~ /$_[1]/ ); |
114
|
0
|
|
|
|
|
|
$no = $no + 1; |
115
|
|
|
|
|
|
|
} |
116
|
0
|
|
|
|
|
|
close ( FILEGREPNO ); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub file_word_replace { |
120
|
0
|
0
|
|
0
|
0
|
|
open ( GREPREPLACE, "$_[0]" ) || die "File not found" ; |
121
|
0
|
|
|
|
|
|
while ( readline *GREPREPLACE ) |
122
|
|
|
|
|
|
|
{ |
123
|
0
|
0
|
|
|
|
|
if ( $_ =~ /$_[1]/ ) |
124
|
|
|
|
|
|
|
{ |
125
|
0
|
|
|
|
|
|
$_ =~ s/$_[1]/$_[2]/; |
126
|
0
|
|
|
|
|
|
print $_; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} |
130
|
0
|
|
|
|
|
|
close ( GREPREPLACE ); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub file_tail { |
136
|
0
|
|
|
0
|
0
|
|
my $no = "1" ; |
137
|
0
|
0
|
|
|
|
|
open ( FILETAIL, "$_[0]") || die "File not found"; |
138
|
0
|
|
|
|
|
|
my @lines = ; |
139
|
0
|
|
|
|
|
|
my $start = $#lines; |
140
|
|
|
|
|
|
|
#my $first = $lines[-1]; |
141
|
|
|
|
|
|
|
#my $len = length ($first ); |
142
|
0
|
0
|
|
|
|
|
print $lines[-1] if ( length($lines[-1]) > 0 ); |
143
|
0
|
|
|
|
|
|
while ($no > 0 ) |
144
|
|
|
|
|
|
|
{ |
145
|
0
|
|
|
|
|
|
my @new_lines = ; |
146
|
0
|
|
|
|
|
|
my $end = $#new_lines; |
147
|
0
|
0
|
|
|
|
|
if ( $start =! $end ) |
148
|
|
|
|
|
|
|
{ |
149
|
0
|
|
|
|
|
|
print $new_lines[-1]; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
0
|
|
|
|
|
|
close(FILETAIL); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1; |
159
|
|
|
|
|
|
|
__END__ |