<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On May 1, 2009, at 1:29 PM, Antonio Sun wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="gmail_quote">Hi Abram, <br><br>When you talked about the difficulties that Perl has calculating string<br>lengths, I didn't quite understand your explanation because I didn't catch<br>the term that you used. Could you explain it in writing please? <br> <br>AFAIK, how Perl interprets string length depends on encoding, E.g.,<br><br><div style="margin-left: 40px;">use encoding utf8;<br>print length("台葉"); # 2, because there are 2 Chinese characters<br># However, <br> no encoding;<br>print length("台葉"); # 6, the 2 Chinese characters take up 6 bytes.<br></div><br>I.e., Perl has the capability to return whatever string length you want. Do I miss anything? <br><br>BTW, <br><br> Anyone knows how to split an Unicode string into individual characters? E.g., from "台葉" to '台' & '葉'?<br></div></blockquote><div><br></div>There has to be a better way than this:</div><div><br></div><div><div><font class="Apple-style-span" face="Courier"> DB<7> @chars = map { chr } unpack('U*', "台葉")</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier"> DB<8> x @chars</font></div><div><font class="Apple-style-span" face="Courier">0 '\x{9A86}'</font></div><div><font class="Apple-style-span" face="Courier">1 '\x{9A7C}'</font></div><div><font class="Apple-style-span" face="Courier"> DB<9> print "@chars"</font></div><div><font class="Apple-style-span" face="Courier">台 葉</font></div><div><font class="Apple-style-span" face="Courier"> DB<10> </font></div><div><br></div></div><div>Mike</div><div><br><blockquote type="cite"><div class="gmail_quote">Thanks<br><font color="#888888"><br>Antonio<br><br> </font></div><br> _______________________________________________<br>toronto-pm mailing list<br><a href="mailto:toronto-pm@pm.org">toronto-pm@pm.org</a><br><a href="http://mail.pm.org/mailman/listinfo/toronto-pm">http://mail.pm.org/mailman/listinfo/toronto-pm</a><br></blockquote></div><br><div apple-content-edited="true"> <span class="Apple-style-span" style="font-size: 12px; "><div style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">-- </div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br class="khtml-block-placeholder"></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Mike Stok <<a href="mailto:mike@stok.ca">mike@stok.ca</a>></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a href="http://www.stok.ca/~mike/">http://www.stok.ca/~mike/</a></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br class="khtml-block-placeholder"></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">The "`Stok' disclaimers" apply.</div><div><br class="khtml-block-placeholder"></div><div><br class="khtml-block-placeholder"></div></div><br class="Apple-interchange-newline"></span> </div><br></body></html>