I see two problems:
  1. Some of the hex dumps are wrong. Are you sure the file is UTF-8 encoded?
  2. To be able to use the characters literally, you need to use utf8 and specify the encoding when openinig the file.
The code below shows how to use both types of constants and how they interact with encodings. It reads its own source code, so you don't need any other additional file for testing.
#! /usr/bin/perl use warnings; use strict; use feature qw{ say }; use utf8; use constant APOSTROPHE => "’" ; use constant OPENQUOTE => "“" ; use constant CLOSEQUOTE => "”" ; use constant COMMA => "¸" ; # Fixed values. use constant APOSTROPHE2 => "\x{e2}\x{80}\x{99}" ; use constant OPENQUOTE2 => "\x{e2}\x{80}\x{9c}" ; use constant CLOSEQUOTE2 => "\x{e2}\x{80}\x{9d}" ; use constant COMMA2 => "\x{c2}\x{b8}" ; for my $encoding ("", ':encoding(UTF-8)') { open my $self, "<$encoding", __FILE__ or die $!; say "Encoding: $encoding"; while (my $line = <$self>) { say "apostrophe in line $." if $line =~ /@{[APOSTROPHE]}/; say "open quote in line $." if $line =~ /@{[OPENQUOTE]}/; say "close quote in line $." if $line =~ /@{[CLOSEQUOTE]}/; say "comma in line $." if $line =~ /@{[COMMA]}/; say "apostrophe2 in line $." if $line =~ /@{[APOSTROPHE2]}/; say "open quote2 in line $." if $line =~ /@{[OPENQUOTE2]}/; say "close quote2 in line $." if $line =~ /@{[CLOSEQUOTE2]}/; say "comma2 in line $." if $line =~ /@{[COMMA2]}/; } }
Output:
Encoding: apostrophe2 in line 7 open quote2 in line 8 close quote2 in line 9 comma in line 10 comma2 in line 10 Encoding: :encoding(UTF-8) apostrophe in line 7 open quote in line 8 close quote in line 9 comma in line 10

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

In reply to Re: Converting Unicode by choroba
in thread Converting Unicode by BernieC

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.