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?
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With