Re: [PATCH @14870] long C<=item>s and other pod->man->troff problems
[p5sagit/p5-mst-13.2.git] / pod / perluniintro.pod
index 3703e10..c94f3d2 100644 (file)
@@ -148,7 +148,7 @@ Unicode strings. Specifically, if all code points in the string are
 Otherwise, it uses UTF-8.
 
 A user of Perl does not normally need to know nor care how Perl
-happens to encodes its internal strings, but it becomes relevant when
+happens to encode its internal strings, but it becomes relevant when
 outputting Unicode strings to a stream without a discipline (one with
 the "default default").  In such a case, the raw bytes used internally
 (the native character set or UTF-8, as appropriate for each string)
@@ -221,6 +221,17 @@ Note that both C<\x{...}> and C<\N{...}> are compile-time string
 constants: you cannot use variables in them.  if you want similar
 run-time functionality, use C<chr()> and C<charnames::vianame()>.
 
+Also note that if all the code points for pack "U" are below 0x100,
+bytes will be generated, just like if you were using C<chr()>.
+
+   my $bytes = pack("U*", 0x80, 0xFF);
+
+If you want to force the result to Unicode characters, use the special
+C<"U0"> prefix.  It consumes no arguments but forces the result to be
+in Unicode characters, instead of bytes.
+
+   my $chars = pack("U0U*", 0x80, 0xFF);
+
 =head2 Handling Unicode
 
 Handling Unicode is for the most part transparent: just use the
@@ -548,7 +559,9 @@ than ASCII 0 to 9 (and ASCII a to f for hexadecimal).
 
 =over 4
 
-=item Will My Old Scripts Break?
+=item 
+
+Will My Old Scripts Break?
 
 Very probably not.  Unless you are generating Unicode characters
 somehow, any old behaviour should be preserved.  About the only
@@ -557,13 +570,17 @@ is the old behaviour of C<chr()> where supplying an argument more
 than 255 produced a character modulo 255 (for example, C<chr(300)>
 was equal to C<chr(45)>).
 
-=item How Do I Make My Scripts Work With Unicode?
+=item 
+
+How Do I Make My Scripts Work With Unicode?
 
 Very little work should be needed since nothing changes until you
 somehow generate Unicode data.  The greatest trick will be getting
 input as Unicode, and for that see the earlier I/O discussion.
 
-=item How Do I Know Whether My String Is In Unicode?
+=item 
+
+How Do I Know Whether My String Is In Unicode?
 
 You shouldn't care.  No, you really shouldn't.  If you have
 to care (beyond the cases described above), it means that we
@@ -592,7 +609,9 @@ and its only defined function C<length()>:
     use bytes;
     print length($unicode), "\n"; # will print 2 (the 0xC4 0x80 of the UTF-8)
 
-=item How Do I Detect Data That's Not Valid In a Particular Encoding
+=item 
+
+How Do I Detect Data That's Not Valid In a Particular Encoding?
 
 Use the C<Encode> package to try converting it.
 For example,
@@ -611,10 +630,13 @@ For UTF-8 only, you can use:
 
 If invalid, a C<Malformed UTF-8 character (byte 0x##) in
 unpack> is produced. The "U0" means "expect strictly UTF-8
-encoded Unicode". Without that the C<unpack("U*", ...)>
-would accept also data like C<chr(0xFF>).
+encoded Unicode".  Without that the C<unpack("U*", ...)>
+would accept also data like C<chr(0xFF>), similarly to the
+C<pack> as we saw earlier.
+
+=item 
 
-=item How Do I Convert Binary Data Into a Particular Encoding, Or Vice Versa?
+How Do I Convert Binary Data Into a Particular Encoding, Or Vice Versa?
 
 This probably isn't as useful as you might think.
 Normally, you shouldn't need to.
@@ -667,12 +689,16 @@ Any random collection of bytes isn't well-formed UTF-8.  You can
 use C<unpack("C*", $string)> for the former, and you can create
 well-formed Unicode data by C<pack("U*", 0xff, ...)>.
 
-=item How Do I Display Unicode?  How Do I Input Unicode?
+=item 
+
+How Do I Display Unicode?  How Do I Input Unicode?
 
 See http://www.hclrss.demon.co.uk/unicode/ and
 http://www.cl.cam.ac.uk/~mgk25/unicode.html
 
-=item How Does Unicode Work With Traditional Locales?
+=item 
+
+How Does Unicode Work With Traditional Locales?
 
 In Perl, not very well.  Avoid using locales through the C<locale>
 pragma.  Use only one or the other.