| 1 | package Search::Equidistance; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use 5.008; | ||||||||
|
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 | 1 | 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 | 1 | our %EXPORT_TAGS = ( 'all' => [ qw() ] ); | |||||||||
| 19 | |||||||||||
| 20 | 1 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||
| 21 | |||||||||||
| 22 | 1 | our @EXPORT = qw(decode); | |||||||||
| 23 | |||||||||||
| 24 | 1 | our $VERSION = '0.01'; | |||||||||
| 25 | |||||||||||
| 26 | # Preloaded methods go here. | ||||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | sub decode { | ||||||||
|
Subroutine
decode: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||
| 29 | 0 | ▶ | croak("Usage: decode(string, max-skip, file) ") unless(@_ == 3); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | |||||||||||
| 31 | 0 | my ($find, $MAXSKIP, $file) = @_; | |||||||||
| 32 | 0 | my $rfind = reverse($find); | |||||||||
| 33 | 0 | ▶ | open F, $file or die "No such file $file: $!\n"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | |||||||||||
| 35 | 0 | my $line = join "", <F>; | |||||||||
| 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) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 0 | $found++; | |||||||||
| 53 | 0 | ▶ | print "[Skip=$n]\n" if ($found == 1); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | $count++; | |||||||||
| 55 | 0 | ▶ | print "<$i:$len>" if ($count == 1); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 0 | $pos += length($`); | |||||||||
| 57 | 0 | print "$&($pos)"; | |||||||||
| 58 | 0 | $pos += length($&); | |||||||||
| 59 | 0 | s/$`$&//; | |||||||||
| 60 | } | ||||||||||
| 61 | 0 | ▶ | print "\n" if ($count > 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 1; | |||||||||
| 70 | __END__ | ||||||||||