if ((my $after = $offset + $lookahead) < $#rows) {
# see how much of it matches the current link
my $trim = 1;
+ pos $link = 0;
for my $match (split //, $rows[$after]) {
scalar $link =~ /\G\Q$match/g or last;
$trim++;
}
# use this link if it's shorter
if ($trim < length $link) {
- $link = substr $rows[$after], 0, $trim;
- # advance lookbehind offset on the next page
$enlarged = 0;
for ($offset + 1 .. $after) {
+ my $prefix = substr $rows[$_], 0, $trim;
+ # advance lookbehind offset on the next page
$shrunk++;
- last if $rows[$_] =~ /^\Q$link/;
+ next if $link =~ /^\Q$prefix/;
+ $link = $prefix;
+ last;
}
}
}