... the _utf8_on() described in 'perldoc Encode' doesn't seem to exist.

It exists, but is not exported by default; either declare that you want this exported on the "use Encode" line, or else qualify the call with the package name:

Encode::_utf8_on( $string ); # sets utf8 flag on $string
Likewise for the "is_utf8( $string )" function.

As mentioned previously, ASCII is a proper subset of utf8; a key feature of utf8's design is that every plain ascii text file is, by definition, a working utf8 file.

Putting a BOM at the start of ASCII data is silly, but if a text file really does contain wide (non-ascii) unicode characters, which will be 2 or 3 bytes long in utf8, an initial BOM can be sort of a handy signature to put at the start of the file, to give users or apps a "heads up" about what the file contains. (It'll show up as the three-byte sequence "0xEF 0xBB 0xBF", which is the utf8 rendering of the 16-bit unicode value U+FEFF.) Still, it is technically unnecessary for utf8 in any case.


In reply to Re: writing UTF-8 files by graff
in thread writing UTF-8 files by orionblue3

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.