in reply to Re^2: Decoding Russian text
in thread Decoding Russian text

You could try different encodings until you find one that works.

This outputs the file decoded using a variety of encodings. It'll be easier to read if file only contains one line.

perl -MEncode -E' binmode(STDIN); binmode(STDOUT, ":encoding(UTF-8)"); $_ = do { local $/; <STDIN> }; for my $enc (Encode->encodings(":all")) { my $dec = eval { decode($enc, $_, Encode::FB_CROAK | Encode::LEAVE_SRC) }; if (defined($dec)) { say "$enc: $dec"; } else { print "$enc: Fail: $@"; } } ' < file

Replace UTF-8 with the encoding your terminal expects.

Replies are listed 'Best First'.
Re^4: Decoding Russian text
by vit (Friar) on Jul 13, 2011 at 21:40 UTC
    By some reason if I put :encoding(UTF-8) to both STDIN and STDOUT it works fine.
    But I want to apply encoding to a single string, not to an input stream. How can I do this ?

      But I want to apply encoding to a single string, not to an input stream.

      uh, that's what the program already does. decode($enc, $str)