line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package File::OldSlurp; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# Copyright (C) 1994-1996, 1998, 2001-2002 David Muir Sharnoff |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
8
|
|
|
|
|
|
|
@EXPORT = qw(read_file write_file overwrite_file append_file read_dir); |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
1166
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
191
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
12
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1794
|
|
13
|
|
|
|
|
|
|
$VERSION = 2004.0430; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub read_file |
16
|
|
|
|
|
|
|
{ |
17
|
6
|
|
|
6
|
0
|
42
|
my ($file) = @_; |
18
|
|
|
|
|
|
|
|
19
|
6
|
100
|
|
|
|
39
|
local($/) = wantarray ? $/ : undef; |
20
|
6
|
|
|
|
|
12
|
local(*F); |
21
|
6
|
|
|
|
|
8
|
my $r; |
22
|
|
|
|
|
|
|
my (@r); |
23
|
|
|
|
|
|
|
|
24
|
6
|
50
|
|
|
|
206
|
open(F, "<$file") || croak "open $file: $!"; |
25
|
6
|
|
|
|
|
125
|
@r = ; |
26
|
6
|
50
|
|
|
|
59
|
close(F) || croak "close $file: $!"; |
27
|
|
|
|
|
|
|
|
28
|
6
|
100
|
|
|
|
38
|
return $r[0] unless wantarray; |
29
|
1
|
|
|
|
|
7
|
return @r; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub write_file |
33
|
|
|
|
|
|
|
{ |
34
|
26
|
|
|
26
|
0
|
267
|
my ($f, @data) = @_; |
35
|
|
|
|
|
|
|
|
36
|
26
|
|
|
|
|
147
|
local(*F); |
37
|
|
|
|
|
|
|
|
38
|
26
|
50
|
|
|
|
22954
|
open(F, ">$f") || croak "open >$f: $!"; |
39
|
26
|
50
|
|
|
|
306
|
(print F @data) || croak "write $f: $!"; |
40
|
26
|
50
|
|
|
|
1560
|
close(F) || croak "close $f: $!"; |
41
|
26
|
|
|
|
|
361
|
return 1; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub overwrite_file |
45
|
|
|
|
|
|
|
{ |
46
|
2
|
|
|
2
|
0
|
433
|
my ($f, @data) = @_; |
47
|
|
|
|
|
|
|
|
48
|
2
|
|
|
|
|
6
|
local(*F); |
49
|
|
|
|
|
|
|
|
50
|
2
|
100
|
|
|
|
48
|
if (-e $f) { |
51
|
1
|
50
|
|
|
|
35
|
open(F, "+<$f") || croak "open +<$f: $!"; |
52
|
|
|
|
|
|
|
} else { |
53
|
1
|
50
|
|
|
|
70
|
open(F, "+>$f") || croak "open >$f: $!"; |
54
|
|
|
|
|
|
|
} |
55
|
2
|
50
|
|
|
|
13
|
(print F @data) || croak "write $f: $!"; |
56
|
2
|
|
|
|
|
5
|
my $where = tell(F); |
57
|
2
|
50
|
|
|
|
13
|
croak "could not tell($f): $!" |
58
|
|
|
|
|
|
|
unless defined $where; |
59
|
2
|
50
|
|
|
|
107
|
truncate(F, $where) |
60
|
|
|
|
|
|
|
|| croak "trucate $f at $where: $!"; |
61
|
2
|
50
|
|
|
|
23
|
close(F) || croak "close $f: $!"; |
62
|
2
|
|
|
|
|
8
|
return 1; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub append_file |
66
|
|
|
|
|
|
|
{ |
67
|
2
|
|
|
2
|
0
|
111
|
my ($f, @data) = @_; |
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
6
|
local(*F); |
70
|
|
|
|
|
|
|
|
71
|
2
|
50
|
|
|
|
107
|
open(F, ">>$f") || croak "open >>$f: $!"; |
72
|
2
|
50
|
|
|
|
12
|
(print F @data) || croak "write $f: $!"; |
73
|
2
|
50
|
|
|
|
54
|
close(F) || croak "close $f: $!"; |
74
|
2
|
|
|
|
|
7
|
return 1; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub read_dir |
78
|
|
|
|
|
|
|
{ |
79
|
3
|
|
|
3
|
0
|
232
|
my ($d) = @_; |
80
|
|
|
|
|
|
|
|
81
|
3
|
|
|
|
|
6
|
my (@r); |
82
|
3
|
|
|
|
|
7
|
local(*D); |
83
|
|
|
|
|
|
|
|
84
|
3
|
50
|
|
|
|
118
|
opendir(D,$d) || croak "opendir $d: $!"; |
85
|
3
|
|
100
|
|
|
199
|
@r = grep($_ ne "." && $_ ne "..", readdir(D)); |
86
|
3
|
50
|
|
|
|
43
|
closedir(D) || croak "closedir $d: $!"; |
87
|
3
|
|
|
|
|
33
|
return @r; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |