];
my $result = 0;
my $added = {};
my %en2ja = (%$exact_data, %$pattern_data);
for (sort {$a cmp $b} keys %en2ja) {
if (/$pattern/) {
$has_match = 1;
$added->{$_} = 1;
$r .= get_match_text ($_, $en2ja{$_}, $pattern);
$r .= q[
...] and last if ++$result == $max_result;
}
}
$result = 0;
my %ja2en = reverse %en2ja;
for (sort {$a cmp $b} keys %ja2en) {
if (/$pattern/) {
next if $added->{$ja2en{$_}};
$has_match = 1;
$r .= get_match_text ($ja2en{$_}, $_, $pattern);
$r .= q[
...] and last if ++$result == $max_result;
}
}
$r .= q[
];
print $r if $has_match;
return $has_match;
} # print_matches
sub get_match_text ($$) {
my ($en, $ja) = @_;
## NOTE: Marking will not work well if it contains &, <, >, or ", or
## the pattern matches with charrefs, e.g. "t" (part of < and ").
my $r = q[