note
Jim
<p>Here's a way to reverse a Unicode string using the regular expression character class [href://http://perldoc.perl.org/perlre.html#Character-Classes-and-other-Special-Escapes|\X] to match Unicode extended grapheme clusters:<p>
<code>
my $edocinU = join '', reverse $Unicode =~ m/\X/g;
</code>
<p>Here's a demonstration using Vietnamese (<i>tiếng Việt</i>) words:</p>
<pre>
#!perl
use strict;
use warnings;
use utf8;
binmode STDOUT, ':encoding(UTF-8)';
my $Moonshine = "Rượu đế";
my $enihsnooM = join '', reverse $Moonshine =~ m/\X/g;
print "$Moonshine\n";
print "$enihsnooM\n";
__END__
Rượu đế
ếđ uợưR
LATIN CAPITAL LETTER R
LATIN SMALL LETTER U
COMBINING HORN
LATIN SMALL LETTER O
COMBINING HORN
COMBINING DOT BELOW
LATIN SMALL LETTER U
SPACE
LATIN SMALL LETTER D WITH STROKE
LATIN SMALL LETTER E
COMBINING CIRCUMFLEX ACCENT
COMBINING ACUTE ACCENT
</pre>
<p>[I was forced to use <pre> tags instead of <code> tags here to display the actual Vietnamese characters rather than their HTML character entities.]</p>
661510
661510