在Unix和Perl中用希腊语搜索单词

时间:2013-02-28 22:47:37

标签: perl unix special-characters

我有希腊语的txt文件,现在我想使用perl和bash搜索其中的特定单词......单词就像?a?,t?,e ??

我正在寻找英语单词,现在想用希腊语代替它们,但我得到的只是???主要是...对于Perl:

my %word = map { $_ => 1 } qw/name date birth/;

和bash

for X in name date birth
do
有人可以帮帮我吗?

1 个答案:

答案 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

注意:

  • 确保源代码使用UTF-8进行编码,并使用use utf8;
  • 确保使用use open行并为数据文件指定适当的编码。 (如果不是UTF-8,请更改它。)