TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Perl Time::Piece Unicode Issue

3 pointsby jjjbokmaalmost 4 years ago

1 comment

nanisalmost 4 years ago
One might want to use Unicode::UTF8[1] instead of the hand-rolled helper:<p><pre><code> #!&#x2F;usr&#x2F;bin&#x2F;perl use strict; use warnings FATAL =&gt; &#x27;utf8&#x27; use open &#x27;:std&#x27;, &#x27;:encoding(UTF-8)&#x27;; use Time::Piece; use Unicode::UTF8 qw( decode_utf8 ); for my $month (1 .. 12) { my $date = sprintf &#x27;2021-%02d-01&#x27;, $month; my $tp = Time::Piece-&gt;strptime($date, &#x27;%Y-%m-%d&#x27;); print decode_utf8($tp-&gt;strftime(&#x27;%B&#x27;)), &#x27; &#x27; x ($month != 12); } print &quot;\n&quot;; </code></pre> &gt; Here is a summary of features for comparison with Encode&#x27;s UTF-8 implementation:<p>&gt; * Simple API which makes use of Perl&#x27;s standard warning categories.<p>&gt; * Recognizes all noncharacters regardless of Perl version<p>&gt; * Implements Unicode&#x27;s recommended practice for using U+FFFD.<p>&gt; * Better diagnostics in warning messages<p>&gt; * Detects and reports inconsistency in Perl&#x27;s internal representation of wide characters (UTF-X)<p>&gt; * Preserves taintedness of decoded $octets or encoded $string<p>&gt; * Better performance ~ 600% - 1200% (JA: 600%, AR: 700%, SV: 900%, EN: 1200%, see benchmarks directory in git repository)<p>[1]: <a href="https:&#x2F;&#x2F;metacpan.org&#x2F;pod&#x2F;Unicode::UTF8" rel="nofollow">https:&#x2F;&#x2F;metacpan.org&#x2F;pod&#x2F;Unicode::UTF8</a>
评论 #27379632 未加载