I know this type of question has been asked many times, but none of the answers are working for me. Here is what I want to do: 1) read a file in UTF-8 encoding 2) do a bunch of processing - character by character, concatenations, substrings, concatenating it with other variables and other constants 3) write the resulting record out in UTF-8 I have tried using "< :encoding(UTF-8)" on the open. It reads it won't read a single line - there is no error message - the program hangs and aborts. I have tried reading a record without encoding and then doing a decode("UTF-8",$_) (note I have put $_ into a variable, and I do chomp it). This works, but reads the file and processes the record just as if it was ASCII. As I understand it, PERL has its own internal encoding. All the variables are in that encoding. If I don't specify a thing I assume the reads and writes default to the machine's encoding which is ASCII (Windows is what I want it to run on). So I think all I have to do is read the input file using encoding, do my work, then encode the result and write the resulting record. It isn't working at all. I did add the "use" as well. And note - I am doing the read with the diamond operator in a while... while (<INFILE>) Any sample program or advice would be much appreciated. I cannot even find a sample program on the internet yet that reads a file and writes some output.

In reply to Read and write UTF-8 by Norah

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.