views:

84

answers:

1

I wrote a small program to go through /usr/share/dict/words finding palindromes

while(<>){
  chomp;
  print "$_\n" if $_ eq reverse;
}

However, this does not work for a list of Danish words encoded in Latin-1 (ISO-8859-1). Just wondering how I'd go about making it work?

+4  A: 

Use locale? And maybe also turn on the Unicode flag on STDIN:

use Modern::Perl;
use locale;
binmode(STDIN, ":utf8");
while (<>) {
    chomp;
    say if $_ eq reverse;
}

Without the binmode it could have been a nice one-liner:

perl -Mlocale -nE 'chomp; say if $_ eq reverse'
zoul
or perl -Mlocale -lnE 'say if $_ eq reverse'
converter42