line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# Toolbox::Simple - Some tools (mostly math-related) to make life easier. |
3
|
|
|
|
|
|
|
# Wrote it for myself, anyone else is welcome to it. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# (c) 2002 Jason Leane |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# See "README" for help. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
BEGIN { |
11
|
1
|
|
|
1
|
|
6710
|
srand; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package Toolbox::Simple; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$VERSION = "0.52"; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
10
|
use Exporter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
19
|
1
|
|
|
1
|
|
1019
|
use Socket; |
|
1
|
|
|
|
|
7235
|
|
|
1
|
|
|
|
|
697
|
|
20
|
1
|
|
|
1
|
|
1059
|
use Sys::Hostname; |
|
1
|
|
|
|
|
1597
|
|
|
1
|
|
|
|
|
64
|
|
21
|
1
|
|
|
1
|
|
6887
|
use MIME::Base64; |
|
1
|
|
|
|
|
827
|
|
|
1
|
|
|
|
|
62
|
|
22
|
1
|
|
|
1
|
|
7
|
use Digest::MD5; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
23
|
1
|
|
|
1
|
|
963
|
use IO::File; |
|
1
|
|
|
|
|
12767
|
|
|
1
|
|
|
|
|
361
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
@EXPORT = qw(); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
@EXPORT_OK = qw(c32 _nl send_mail md5_file b64_encode b64_decode my_hostname my_ip round_money commify_number hex2ascii ip2name name2ip fibo gcd gcf lcm is_prime dec2hex hex2dec dec2bin bin2dec dec2oct oct2dec time_now time_english); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub average { |
33
|
0
|
|
|
0
|
0
|
0
|
my $nums = scalar(@_); |
34
|
0
|
|
|
|
|
0
|
my $n = 0; |
35
|
0
|
|
|
|
|
0
|
my $total = 0; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
foreach $n (@_) { |
38
|
0
|
|
|
|
|
0
|
$total = $total + $n; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
0
|
my $avg = $total / $nums; |
42
|
0
|
|
|
|
|
0
|
return($avg); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub fibo { |
46
|
1
|
|
|
1
|
1
|
504
|
my ($n, $s) = (shift, sqrt(5)); |
47
|
1
|
|
|
|
|
17
|
return int((((0.5 + 0.5*$s) ** $n) - ((0.5 - 0.5*$s) ** $n)) / $s); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub gcd { |
51
|
1
|
|
|
1
|
|
1190
|
use integer; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
5
|
|
52
|
0
|
|
0
|
0
|
1
|
0
|
my $gcd = shift || 1; |
53
|
0
|
|
|
|
|
0
|
while (@_) { |
54
|
0
|
|
|
|
|
0
|
my $next = shift; |
55
|
0
|
|
|
|
|
0
|
while($next) { |
56
|
0
|
|
|
|
|
0
|
my $r = $gcd % $next; |
57
|
0
|
0
|
|
|
|
0
|
$r += $next if $r < 0; |
58
|
0
|
|
|
|
|
0
|
$gcd = $next; |
59
|
0
|
|
|
|
|
0
|
$next = $r; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
1
|
|
|
1
|
|
77
|
no integer; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
63
|
0
|
|
|
|
|
0
|
return $gcd; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub gcf { |
67
|
1
|
|
|
1
|
|
45
|
use integer; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
68
|
0
|
|
0
|
0
|
1
|
0
|
my $gcf = shift || 1; |
69
|
0
|
|
|
|
|
0
|
while (@_) { |
70
|
0
|
|
|
|
|
0
|
my $next = shift; |
71
|
0
|
|
|
|
|
0
|
while($next) { |
72
|
0
|
|
|
|
|
0
|
my $r = $gcf % $next; |
73
|
0
|
0
|
|
|
|
0
|
$r += $next if $r < 0; |
74
|
0
|
|
|
|
|
0
|
$gcf = $next; |
75
|
0
|
|
|
|
|
0
|
$next = $r; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
1
|
|
|
1
|
|
76
|
no integer; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
79
|
0
|
|
|
|
|
0
|
return $gcf; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub lcm { |
83
|
1
|
|
|
1
|
|
84
|
use integer; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
84
|
0
|
|
|
0
|
1
|
0
|
my $lcm = shift; |
85
|
0
|
|
|
|
|
0
|
foreach (@_) { $lcm *= $_ / gcd($_, $lcm) } |
|
0
|
|
|
|
|
0
|
|
86
|
1
|
|
|
1
|
|
56
|
no integer; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
87
|
0
|
|
|
|
|
0
|
return $lcm; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub is_prime { |
91
|
|
|
|
|
|
|
# Hella props to Miller & Rabin |
92
|
1
|
|
|
1
|
|
43
|
use integer; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
93
|
2
|
|
|
2
|
1
|
3
|
my $n = shift; |
94
|
2
|
|
|
|
|
3
|
my $n1 = $n - 1; |
95
|
2
|
|
|
|
|
4
|
my $one = $n - $n1; |
96
|
2
|
|
|
|
|
2
|
my $wit = $one * 100; |
97
|
2
|
|
|
|
|
4
|
my $wit_count; |
98
|
|
|
|
|
|
|
|
99
|
2
|
|
|
|
|
2
|
my $p2 = $one; |
100
|
2
|
|
|
|
|
2
|
my $p2i = -1; |
101
|
2
|
|
|
|
|
9
|
++$p2i, $p2 *= 2 while $p2 <= $n1; |
102
|
2
|
|
|
|
|
20
|
$p2 /= 2; |
103
|
|
|
|
|
|
|
|
104
|
2
|
|
|
|
|
2
|
my $last_wit = 5; |
105
|
2
|
50
|
|
|
|
5
|
$last_wit += (260 - $p2i)/13 if $p2i < 260; |
106
|
|
|
|
|
|
|
|
107
|
2
|
|
|
|
|
4
|
for $wit_count ( 1..$last_wit ) { |
108
|
55
|
|
|
|
|
46
|
$wit *= 1024; |
109
|
55
|
|
|
|
|
55
|
$wit += rand(1024); |
110
|
55
|
50
|
|
|
|
76
|
$wit = $wit % $n if $wit > $n; |
111
|
55
|
100
|
|
|
|
79
|
$wit = $one * 100, redo if $wit == 0; |
112
|
|
|
|
|
|
|
|
113
|
48
|
|
|
|
|
37
|
my $prod = $one; |
114
|
48
|
|
|
|
|
35
|
my $n1bits = $n1; |
115
|
48
|
|
|
|
|
39
|
my $p2next = $p2; |
116
|
|
|
|
|
|
|
|
117
|
48
|
|
|
|
|
40
|
while(1) { |
118
|
168
|
|
100
|
|
|
342
|
my $rootone = $prod == 1 || $prod == $n1; |
119
|
168
|
|
|
|
|
139
|
$prod = ($prod * $prod) % $n; |
120
|
168
|
50
|
66
|
|
|
400
|
return 0 if $prod == 1 && !$rootone; |
121
|
|
|
|
|
|
|
|
122
|
168
|
100
|
|
|
|
249
|
if($n1bits >= $p2next) { |
123
|
96
|
|
|
|
|
83
|
$prod = ($prod * $wit) % $n; |
124
|
96
|
|
|
|
|
84
|
$n1bits -= $p2next; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
168
|
100
|
|
|
|
225
|
last if $p2next == 1; |
128
|
120
|
|
|
|
|
101
|
$p2next /= 2; |
129
|
|
|
|
|
|
|
} |
130
|
48
|
50
|
|
|
|
773
|
return 0 unless $prod == 1; |
131
|
|
|
|
|
|
|
} |
132
|
1
|
|
|
1
|
|
229
|
no integer; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
133
|
2
|
|
|
|
|
10
|
return 1; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub dec2hex { |
137
|
0
|
|
|
0
|
1
|
0
|
my $dec = int(shift); |
138
|
0
|
|
|
|
|
0
|
my $pref; |
139
|
0
|
0
|
|
|
|
0
|
if(shift) { $pref = '0x' } else { $pref = '' } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
140
|
0
|
|
|
|
|
0
|
my $hex = $pref . sprintf("%x", $dec); |
141
|
0
|
|
|
|
|
0
|
return($hex); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub hex2dec { |
145
|
3
|
|
|
3
|
1
|
13
|
my $h = shift; |
146
|
3
|
|
|
|
|
5
|
$h =~ s/^0x//g; |
147
|
3
|
|
|
|
|
11
|
return(hex($h)); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub dec2oct { |
151
|
0
|
|
|
0
|
1
|
0
|
my $dec = int(shift); |
152
|
0
|
|
|
|
|
0
|
my $oct = sprintf("%o", $dec); |
153
|
0
|
|
|
|
|
0
|
return($oct); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub oct2dec { |
157
|
1
|
|
|
1
|
1
|
3
|
my $o = shift; |
158
|
1
|
|
|
|
|
7
|
return(oct($o)); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub dec2bin { |
162
|
0
|
|
|
0
|
1
|
0
|
my $dec = int(shift); |
163
|
0
|
|
|
|
|
0
|
my $bits = shift; |
164
|
0
|
|
|
|
|
0
|
my $bin = unpack("B32", pack("N", $dec)); |
165
|
0
|
|
|
|
|
0
|
substr($bin, 0, (32 - $bits)) = ''; |
166
|
0
|
|
|
|
|
0
|
return($bin); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub bin2dec { |
170
|
1
|
|
|
1
|
1
|
3
|
my $bin = shift; |
171
|
1
|
|
|
|
|
2
|
my $bits = length($bin); |
172
|
1
|
|
|
|
|
5
|
$bin = (32 - $bits) x '0' . $bin; |
173
|
1
|
|
|
|
|
11
|
my $dec = unpack("N", pack("B32", substr("0" x 32 . $bin, -32))); |
174
|
1
|
|
|
|
|
4
|
return($dec); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub round_money { |
178
|
4
|
|
|
4
|
1
|
7
|
my $f = shift; |
179
|
4
|
50
|
|
|
|
14
|
if($f == int($f)) { return($f); } |
|
0
|
|
|
|
|
0
|
|
180
|
4
|
|
|
|
|
32
|
my $r = sprintf("%.2f", $f); |
181
|
4
|
|
|
|
|
13
|
return($r); |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub time_english { |
185
|
|
|
|
|
|
|
# Format = time | date_short | date_long | weekday | month | year | date_lf |
186
|
1
|
|
|
1
|
1
|
2
|
my $fmt = shift; |
187
|
1
|
|
|
|
|
5
|
my @days = qw(Sunday Monday Tuesday Wednesday Thursday Friday); |
188
|
1
|
|
|
|
|
6
|
my @months = qw(January February March April May June July August September October November December); |
189
|
1
|
|
|
|
|
18
|
my @t = localtime(time); |
190
|
1
|
50
|
|
|
|
5
|
if(length($t[0]) == 1) { $t[0] = '0' . $t[0] } |
|
0
|
|
|
|
|
0
|
|
191
|
1
|
50
|
|
|
|
4
|
if(length($t[1]) == 1) { $t[1] = '0' . $t[1] } |
|
1
|
|
|
|
|
2
|
|
192
|
1
|
50
|
|
|
|
4
|
if(length($t[2]) == 1) { $t[2] = '0' . $t[2] } |
|
0
|
|
|
|
|
0
|
|
193
|
1
|
|
|
|
|
4
|
my $tm = $t[2] . ':' . $t[1] . ':' . $t[0]; |
194
|
1
|
|
|
|
|
6
|
my $d_long = $days[$t[6]] . ", " . $months[$t[4]] . " $t[3], " . ($t[5] + 1900); |
195
|
1
|
50
|
|
|
|
10
|
return $tm if $fmt eq 'time'; |
196
|
0
|
0
|
|
|
|
0
|
$t[3]++; if(length($t[3]) == 1) { $t[3] = '0' . $t[3] } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
197
|
0
|
0
|
|
|
|
0
|
$t[4]++; if(length($t[4]) == 1) { $t[4] = '0' . $t[4] } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
198
|
0
|
|
|
|
|
0
|
my $d_short = $t[4] . '/' . $t[3] . '/' . ($t[5] + 1900); |
199
|
0
|
|
|
|
|
0
|
my $d_lf = $t[3] . '/' . $t[4] . '/' . ($t[5] + 1900); |
200
|
0
|
0
|
|
|
|
0
|
return $d_long if $fmt eq 'date_long'; |
201
|
0
|
0
|
|
|
|
0
|
return $d_short if $fmt eq 'date_short'; |
202
|
0
|
0
|
|
|
|
0
|
return $d_lf if $fmt eq 'date_lf'; |
203
|
0
|
0
|
|
|
|
0
|
return $days[(localtime(time))[6]] if $fmt eq 'weekday'; |
204
|
0
|
0
|
|
|
|
0
|
return $months[(localtime(time))[4]] if $fmt eq 'month'; |
205
|
0
|
0
|
|
|
|
0
|
return $t[5] + 1900 if $fmt eq 'year'; |
206
|
0
|
|
|
|
|
0
|
return 0; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub time_now { |
210
|
1
|
|
|
1
|
1
|
53
|
my @t = localtime(time); |
211
|
1
|
50
|
|
|
|
7
|
if(length($t[0]) == 1) { $t[0] = '0' . $t[0] } |
|
0
|
|
|
|
|
0
|
|
212
|
1
|
50
|
|
|
|
4
|
if(length($t[1]) == 1) { $t[1] = '0' . $t[1] } |
|
1
|
|
|
|
|
3
|
|
213
|
1
|
50
|
|
|
|
4
|
if(length($t[2]) == 1) { $t[2] = '0' . $t[2] } |
|
0
|
|
|
|
|
0
|
|
214
|
1
|
|
|
|
|
4
|
my $tm = $t[2] . ':' . $t[1] . ':' . $t[0]; |
215
|
1
|
|
|
|
|
6
|
return($tm); |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub name2ip { |
219
|
0
|
|
|
0
|
1
|
0
|
my $host = shift; |
220
|
0
|
|
|
|
|
0
|
my ($addr) = (gethostbyname($host))[4]; |
221
|
0
|
|
|
|
|
0
|
my $ip = join(".", unpack("C4", $addr)); |
222
|
0
|
|
|
|
|
0
|
return($ip); |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub ip2name { |
226
|
0
|
|
|
0
|
1
|
0
|
my $ip = shift; |
227
|
0
|
|
|
|
|
0
|
my $ia = inet_aton($ip); |
228
|
0
|
|
|
|
|
0
|
my $name = scalar(gethostbyaddr($ia, AF_INET)); |
229
|
0
|
0
|
|
|
|
0
|
if($name) { return($name) } else { return(0) } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
sub hex2ascii { |
233
|
1
|
|
|
1
|
1
|
3
|
my $hex = shift; |
234
|
1
|
|
|
|
|
7
|
return(chr(hex($hex))); |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
sub commify_number { |
238
|
|
|
|
|
|
|
# Props to Larry, as always |
239
|
1
|
|
|
1
|
1
|
2
|
my $num = shift; |
240
|
1
|
|
|
|
|
15
|
1 while $num =~ s/(\d)(\d\d\d)(?!\d)/$1,$2/; |
241
|
1
|
|
|
|
|
11
|
return($num); |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
sub send_mail { |
245
|
0
|
|
|
0
|
1
|
0
|
my $srv = shift; |
246
|
0
|
|
|
|
|
0
|
my $to = shift; |
247
|
0
|
|
|
|
|
0
|
my $from = shift; |
248
|
0
|
|
|
|
|
0
|
my $subject = shift; |
249
|
0
|
|
|
|
|
0
|
my $msg = shift; |
250
|
0
|
|
|
|
|
0
|
my @msglines = split(/\n/, $msg); |
251
|
0
|
0
|
|
|
|
0
|
unless($msg =~ /\n/) { $msglines[0] = $msg; } |
|
0
|
|
|
|
|
0
|
|
252
|
|
|
|
|
|
|
|
253
|
1
|
|
|
1
|
|
2229
|
use Net::SMTP; |
|
1
|
|
|
|
|
41131
|
|
|
1
|
|
|
|
|
803
|
|
254
|
|
|
|
|
|
|
|
255
|
0
|
0
|
|
|
|
0
|
my $smtp = Net::SMTP->new($srv) or return(0); |
256
|
0
|
|
|
|
|
0
|
$smtp->mail($from); |
257
|
0
|
|
|
|
|
0
|
$smtp->to($to); |
258
|
0
|
|
|
|
|
0
|
$smtp->data(); |
259
|
0
|
|
|
|
|
0
|
$smtp->datasend("To: $to\n"); |
260
|
0
|
|
|
|
|
0
|
$smtp->datasend("From: $from\n"); |
261
|
0
|
|
|
|
|
0
|
$smtp->datasend("Subject: $subject\n"); |
262
|
0
|
|
|
|
|
0
|
$smtp->datasend("X-Mailer: Toolbox-Simple v0.5 (Perl)\n\n"); |
263
|
0
|
|
|
|
|
0
|
foreach $e (@msglines) { |
264
|
0
|
|
|
|
|
0
|
$smtp->datasend("$e\n"); |
265
|
|
|
|
|
|
|
} |
266
|
0
|
|
|
|
|
0
|
$smtp->dataend(); |
267
|
0
|
|
|
|
|
0
|
$smtp->quit; |
268
|
0
|
|
|
|
|
0
|
return(1); |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
sub my_hostname { |
272
|
1
|
|
|
1
|
1
|
6
|
return(hostname); |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
sub my_ip { |
276
|
0
|
|
|
0
|
1
|
0
|
return(&name2ip(hostname)); |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
sub b64_encode { |
280
|
0
|
|
|
0
|
1
|
0
|
my $file = shift; |
281
|
0
|
|
0
|
|
|
0
|
my $out = shift || "$file.b64"; |
282
|
0
|
0
|
|
|
|
0
|
open(BINP, $file) or return(0); |
283
|
0
|
0
|
|
|
|
0
|
open(BOUTP, ">$out") or return(0); |
284
|
0
|
|
|
|
|
0
|
while(read(BINP, $buf, 60*57)) { |
285
|
0
|
|
|
|
|
0
|
print(BOUTP encode_base64($buf)); |
286
|
|
|
|
|
|
|
} |
287
|
0
|
|
|
|
|
0
|
close(BINP); |
288
|
0
|
|
|
|
|
0
|
close(BOUTP); |
289
|
0
|
|
|
|
|
0
|
return(1); |
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
sub b64_decode { |
293
|
0
|
|
|
0
|
1
|
0
|
my $file = shift; |
294
|
0
|
|
0
|
|
|
0
|
my $out = shift || "$file.out"; |
295
|
0
|
0
|
|
|
|
0
|
open(BINP, $file) or return(0); |
296
|
0
|
0
|
|
|
|
0
|
open(BOUTP, ">$out") or return(0); |
297
|
0
|
|
|
|
|
0
|
while() { |
298
|
0
|
|
|
|
|
0
|
print(BOUTP decode_base64($_)); |
299
|
|
|
|
|
|
|
} |
300
|
0
|
|
|
|
|
0
|
close(BINP); |
301
|
0
|
|
|
|
|
0
|
close(BOUTP); |
302
|
0
|
|
|
|
|
0
|
return(1); |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
sub md5_file { |
306
|
2
|
|
|
2
|
1
|
5
|
my $file = shift; |
307
|
2
|
|
|
|
|
15
|
my $md5 = Digest::MD5->new; |
308
|
2
|
50
|
|
|
|
56
|
open(MDFILE, "<$file") or return(0); |
309
|
2
|
|
|
|
|
6
|
binmode(MDFILE); |
310
|
2
|
|
|
|
|
44
|
$md5->addfile(*MDFILE); |
311
|
2
|
|
|
|
|
15
|
my $dig = $md5->hexdigest; |
312
|
2
|
|
|
|
|
19
|
close(MDFILE); |
313
|
2
|
|
|
|
|
3
|
undef $md5; |
314
|
2
|
|
|
|
|
16
|
return($dig); |
315
|
|
|
|
|
|
|
} |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
sub _nl { |
318
|
0
|
|
|
0
|
|
|
return("\n"); |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
sub c32 { |
322
|
0
|
|
|
0
|
1
|
|
my $data = shift; |
323
|
0
|
|
|
|
|
|
my $c = unpack("%32C*", $data) % 32767; |
324
|
0
|
|
|
|
|
|
return(sprintf("%x", $c)); |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
return 1; |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
__END__ |