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