Use a constructed regular expression to perform the matching on the keys:
use strict; use warnings; use encoding 'UTF8'; my $aData = <<ADATA; This is a boy. ハンカ She is a girl. I am a man. This apple is big. That orange is small. ADATA my $bData = <<BDATA; is a ハンカ small BDATA open my $inB, "<:utf8", \$bData; my (@keys) = <$inB>; close ($inB); chomp @keys; my $match = join '|', sort {length $b <=> length $a} @keys; $match = qr{($match)}; open my $inA, "<:utf8", \$aData; while (defined (my $line = <$inA>)) { print "Found '$1' in line $.:\n $line" if $line =~ $match; }
Prints:
Found 'is a' in line 1: This is a boy. Found 'ハンカ' in line 2: ハンカ Found 'is a' in line 3: She is a girl. Found 'is a' in line 5: This apple is big. Found 'small' in line 6: That orange is small.
Note: I don't seem to be able to paste ハンカ into the code blocks. Replace the entities with the actual string for correct behaviour.
In reply to Re: Compare two files with Japanese and English data
by GrandFather
in thread Compare two files with Japanese and English data
by solukas
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |