我写了一个小程序来通过 /usr/share/dict/words 寻找回文
while(<>){
chomp;
print "$_\n" if $_ eq reverse;
}
但是,这不适用于以 Latin-1 (ISO-8859-1) 编码的丹麦语单词列表。 只是想知道我将如何让它发挥作用?
最佳答案
使用locale ?也许还可以在 STDIN 上打开 Unicode 标志:
use Modern::Perl;
use locale;
binmode(STDIN, ":utf8");
while (<>) {
chomp;
say if $_ eq reverse;
}
如果没有 binmode
,它可能是一个不错的单行代码:
perl -Mlocale -nE 'chomp; say if $_ eq reverse'
关于Perl iso-8859-1 字符串比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2202702/