in reply to Reading File with Czech text inside

The second snippet without a temp file:

use Encode qw( decode ); my $url = "http://ufal.mff.cuni.cz/~hajic/courses/npfl067/TEXTCZ1.txt" +; my $content = decode('iso-8859-2', get($url));

Encode

If you also want to write to the files,

{ open my $FH, ">:encoding(iso-8859-2)", 'file_iso-8859-2.txt' or die "$!\n"; print $FH $content; } { open my $FH, ">:encoding(utf-8)", 'file_utf-8.txt' or die "$!\n"; print $FH $content; }

Replies are listed 'Best First'.
Re^2: Reading File with Czech text inside
by fibokowalsky (Initiate) on Mar 02, 2011 at 14:07 UTC
    Thank u for the reply. Using get, I can read the text normally in utf8 but I want to read already downloaded file with open my $FILE .... "filename";. The script should not require connection.

      If the file is encoded using iso-8859-2 (like file_iso-8859-2.txt above),

      open my $FH, "<:encoding(iso-8859-2)", 'file_iso-8859-2.txt' or die "$!\n";

      If the file is encoded using UTF-8 (like file_utf-8.txt above),

      open my $FH, "<:encoding(UTF-8)", 'file_utf-8.txt' or die "$!\n";