This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
mktables: Use chr() instead of pack()
authorKarl Williamson <khw@cpan.org>
Sun, 24 Aug 2014 16:12:49 +0000 (10:12 -0600)
committerKarl Williamson <khw@cpan.org>
Tue, 21 Oct 2014 15:26:49 +0000 (09:26 -0600)
The input is the native code point, not the Unicode one, and so it is a
bug that pack(U) works.  The W format is what should be used, but I
think chr() is easier to read.

lib/unicore/mktables

index ffbfe74..a21aa1a 100644 (file)
@@ -6999,11 +6999,14 @@ END
                     }
                 }
 
-                # I (khw) have never waded through this line to
-                # understand it well enough to comment it.
+                # The unpack yields a list of the bytes that comprise the
+                # UTF-8 of $code_point, which are each placed in \xZZ format
+                # and output in the %s to map to $tostr, so the result looks
+                # like:
+                # "\xC4\xB0" => "\x{0069}\x{0307}",
                 my $utf8 = sprintf(qq["%s" => "$tostr",],
                         join("", map { sprintf "\\x%02X", $_ }
-                            unpack("U0C*", pack("U", $code_point))));
+                            unpack("U0C*", chr $code_point)));
 
                 # Add a comment so that a human reader can more easily
                 # see what's going on.