G'day YenForYang,

Given you wrote "... I realize that the impact is going to be miniscule.", you should not allow it to affect your choices. Bear in mind that the utf8 pragma is lexically scoped: you could write your code such that it only affects a small portion of it; that portion could be just compile time code (see further down for examples).

I would be more concerned with readability and maintainability. You haven't provided any information on what characters you'll be using nor who'll be reading the code; as a result, what follows are just general thoughts and ideas.

Putting the actual character, its hexadecimal value, or its official Unicode name in code is often not helpful; for instance, seeing any of these in source code would not be immediately meaningful to me:

By the way, they're all the same character:

$ perl -C -E 'use utf8; my @x = ("對", "\x{5c0d}", "\N{CJK UNIFIED IDEOGRAPH-5C0D}"); say for @x'
對
對
對

As you're only dealing with a small number, perhaps use constants with meaningful names:

{ use utf8; use constant { SOME_MEANINGFUL_NAME => "\N{...}", OTHER_MEANINGFUL_NAME => "\N{...}", ... }; }

Some quick tests to demonstrate:

$ perl -C -E '{use utf8; use constant { X => "λ", Y => "Д" }; } say X'
λ
$ perl -C -E '{use utf8; use constant { X => "λ", Y => "Д" }; } say X; say "對"'
λ
å°
$ perl -C -E '{use utf8; use constant { X => "λ", Y => "Д" }; } say X; use utf8; say "對"'
λ
對

You mentioned that you thought the hex sequence was "tedious to lookup". Let Perl do it for you. Write a small script for yourself, the guts of which might look something like this:

$ perl -E 'use utf8; printf "%x\n", ord "對"'
5c0d

And, if you want the official Unicode name, Perl can do that for you too. Here's an example:

perl -E 'use utf8; use Unicode::UCD "charinfo"; say charinfo(ord "對")->{name}'
CJK UNIFIED IDEOGRAPH-5C0D

Unicode::UCD is a core module. It can provide a lot more information about characters than just the name. UCD stands for "Unicode Character Database".

— Ken


In reply to Re: Other effects of 'use utf8' on script by kcott
in thread Other effects of 'use utf8' on script by YenForYang

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.