<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jan 31, 2014 at 3:58 AM, Will Crawford <span dir="ltr">&lt;<a href="mailto:billcrawford1970@gmail.com" target="_blank">billcrawford1970@gmail.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><br>
</div>If the string has been decoded *from* UTF-8 to Perl&#39;s internal<br>
representation, it&#39;s *not* going to be marked as UTF8 internally; it<br>
*shouldn&#39;t* be. It&#39;s no longer a &quot;UTF8&quot; string but a &quot;Unicode&quot; string,<br>
complete with wide characters. If anything, the internal &quot;UTF8&quot; flag<br>
means &quot;this string needs decoding&quot; rather than &quot;has been decoded&quot;.<br></blockquote><div><br></div><div><br></div><div><div>$ perl -le &#39;use Encode;  my $chars = decode_utf8( &quot;bytes&quot; ); print Encode::is_utf8( $chars ) ? &quot;Is flagged utf8\n&quot; : &quot;not flagged\n&quot;; use Devel::Peek; Dump($chars)&#39;</div>


<div>Is flagged utf8</div><div><br></div><div>SV = PV(0x7fb8c10023f0) at 0x7fb8c102b6a8</div><div>  REFCNT = 1</div><div>  FLAGS = (PADMY,POK,pPOK,UTF8)</div><div>  PV = 0x7fb8c0e01170 &quot;bytes&quot;\0 [UTF8 &quot;bytes&quot;]</div>


<div>  CUR = 5</div><div>  LEN = 16</div></div><div><br></div><div><div>Everything is encoded.   The flag tells Perl that its internal representation is encoded as utf8 so knows to work with it as utf8 characters (e.g. length() is length of chars, matching works on chars, etc.)</div>


</div><div><br></div><div><div>$ perl -le &#39;use Encode;  my $chars = decode( &#39;latin1&#39;, &quot;bytes&quot; ); print Encode::is_utf8( $chars ) ? &quot;Is flagged utf8\n&quot; : &quot;not flagged\n&quot;; use Devel::Peek; Dump($chars)&#39;</div>


<div>Is flagged utf8</div><div><br></div><div><br></div></div><div> </div></div>-- <br>Bill Moseley<br><a href="mailto:moseley@hank.org" target="_blank">moseley@hank.org</a>
</div></div>