line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Search::Equidistance; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
77418
|
use 5.008; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
47
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
781
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
12
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
13
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# This allows declaration use Search::Equidistance ':all'; |
16
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
17
|
|
|
|
|
|
|
# will save memory. |
18
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw() ] ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our @EXPORT = qw(decode); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Preloaded methods go here. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub decode { |
29
|
0
|
0
|
|
0
|
0
|
|
croak("Usage: decode(string, max-skip, file) ") unless(@_ == 3); |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
my ($find, $MAXSKIP, $file) = @_; |
32
|
0
|
|
|
|
|
|
my $rfind = reverse($find); |
33
|
0
|
0
|
|
|
|
|
open F, $file or die "No such file $file: $!\n"; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $line = join "", ; |
36
|
0
|
|
|
|
|
|
$line =~ s/(\W|\n)//g; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my ($sum_count, $n, $found, $sm, $i, $end, $match, $len, $pos, $count); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
$sum_count = 0; |
41
|
0
|
|
|
|
|
|
for $n (1..$MAXSKIP) { |
42
|
0
|
|
|
|
|
|
$found = 0; |
43
|
0
|
|
|
|
|
|
$sm = $n - 1; |
44
|
0
|
|
|
|
|
|
for $i (0..$sm) { |
45
|
0
|
|
|
|
|
|
$end = $sm - $i; |
46
|
0
|
|
|
|
|
|
$match = "\.\{0,$i\}\(\.{0,1}\)\.\{0\,$end\}"; |
47
|
0
|
|
|
|
|
|
($_ = $line) =~ s/$match/$1/g; |
48
|
0
|
|
|
|
|
|
$len = length; |
49
|
0
|
|
|
|
|
|
$pos = 0; |
50
|
0
|
|
|
|
|
|
$count = 0; |
51
|
0
|
|
|
|
|
|
while (/$find|$rfind/i) { |
52
|
0
|
|
|
|
|
|
$found++; |
53
|
0
|
0
|
|
|
|
|
print "[Skip=$n]\n" if ($found == 1); |
54
|
0
|
|
|
|
|
|
$count++; |
55
|
0
|
0
|
|
|
|
|
print "<$i:$len>" if ($count == 1); |
56
|
0
|
|
|
|
|
|
$pos += length($`); |
57
|
0
|
|
|
|
|
|
print "$&($pos)"; |
58
|
0
|
|
|
|
|
|
$pos += length($&); |
59
|
0
|
|
|
|
|
|
s/$`$&//; |
60
|
|
|
|
|
|
|
} |
61
|
0
|
0
|
|
|
|
|
print "\n" if ($count > 0); |
62
|
0
|
|
|
|
|
|
$sum_count += $count; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
0
|
|
|
|
|
|
print "\n=== String $find are found $sum_count times (forward & reverse) ===\n"; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
__END__ |