Hello Monks, - I want to read data from the file and process it but there is a problem with character encoding. http://ufal.mff.cuni.cz/~hajic/courses/npfl067/TEXTCZ1.txt Simply, I am not able to read file, convert content in utf8 and and print correctly to STDOUT. I tried opening with: UTF16 (detected by guess_encoding from Encode::Guess) and UCS-2 (detected by enca in Unix) but I couldn't;
open my $FILE, "<:encoding(UCS-2)", 'TEXTCZ1.txt' or die "Cannot open +the TEXTCZ1.txt! \n"; my $content = do { local $/; <$FILE> };
I can get the text in utf8 in different way but that's not nice, like:
my $text = get("http://ufal.mff.cuni.cz/~hajic/courses/npfl067/TEXTCZ1 +.txt"); open my $FILE, '>', 'file.txt' or die "$!\n"; print $FILE $text; open $FILE, "<:encoding(iso-8859-2)", 'file.txt' or die "$!\n"; open my $NEWFILE, ">:encoding(utf-8)", 'fileutf8.txt' or die "$!\n"; print $NEWFILE $_ while <$FILE>; open $FILE, "<:encoding(utf-8)", 'fileutf8.txt' or die "$!\n"; $content = do { local $/; <$FILE> };
Do you have any suggestions to reda directly from file as utf8? I also do not know why text from get() is different than in the file.

In reply to Reading File with Czech text inside by fibokowalsky

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.