Note: you only get away succeed with what you did, because Portuguese uses Latin1, and because utf8::decode modifies its argument even on failure (which is surprising).

The utf8::decode expects octets, but you're trying to feed it with proper Unicode. Of course it fails (check return value), but nevertheless, for whatever vague reason, it converts the utf8 string to latin1-encoded string, -- only when, it seems, such conversion is possible.

use strict; use warnings; use utf8; my $x1 = my $x2 = 'ç'; die if utf8::decode($x2); use Devel::Peek; Dump $x1; Dump $x2;

>perl test170921.pl SV = PV(0xe1af88) at 0xd23560 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK,UTF8) PV = 0xd6b458 "\303\247"\0 [UTF8 "\x{e7}"] CUR = 2 LEN = 10 COW_REFCNT = 1 SV = PV(0xe1af58) at 0xd22fc0 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0xd6b5a8 "\347"\0 CUR = 1 LEN = 10

So this encoding from utf8 to latin1 (even though you did it inadvertently with call to decode) is just a special narrow case of what I wrote in this thread about encoding to your system codepage when reaching outside from Perl, and decoding whatever you fetch back.


In reply to Re^2: Accent file names issue by vr
in thread Accent file names issue by ruimelo73

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.