我有希腊语的txt文件,现在我想使用perl和bash搜索其中的特定单词......单词就像?a?,t?,e ??
我正在寻找英语单词,现在想用希腊语代替它们,但我得到的只是???主要是...对于Perl:
my %word = map { $_ => 1 } qw/name date birth/;
和bash
for X in name date birth
do
有人可以帮帮我吗?
答案 0 :(得分:2)
#!/usr/bin/perl
use strict;
use warnings;
# Tell Perl your code is encoded using UTF-8.
use utf8;
# Tell Perl input and output is encoded using UTF-8.
use open ':std', ':encoding(UTF-8)';
my @words = qw( καί τό εἰς );
my %words = map { $_ => 1 } @words;
my $pat = join '|', map quotemeta, keys %words;
while (<>) {
if (/$pat/) {
print;
}
}
用法:
script.pl file.in >file.out
注意:
use utf8;
。use open
行并为数据文件指定适当的编码。 (如果不是UTF-8,请更改它。)