Debian Codegraph @

upstream/debian-unstable/man1/perlebcdic.1

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "PERLEBCDIC 1"
58 .TH PERLEBCDIC 1 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide"
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 perlebcdic \- Considerations for running Perl on EBCDIC platforms
65 .SH DESCRIPTION
66 .IX Header "DESCRIPTION"
67 An exploration of some of the issues facing Perl programmers
68 on EBCDIC based computers.
69 .PP
70 Portions of this document that are still incomplete are marked with XXX.
71 .PP
72 Early Perl versions worked on some EBCDIC machines, but the last known
73 version that ran on EBCDIC was v5.8.7, until v5.22, when the Perl core
74 again works on z/OS. Theoretically, it could work on OS/400 or Siemens'
75 BS2000 (or their successors), but this is untested. In v5.22 and 5.24,
76 not all
77 the modules found on CPAN but shipped with core Perl work on z/OS.
78 .PP
79 If you want to use Perl on a non\-z/OS EBCDIC machine, please let us know
80 at <https://github.com/Perl/perl5/issues>.
81 .PP
82 Writing Perl on an EBCDIC platform is really no different than writing
83 on an "ASCII" one, but with different underlying numbers, as we'll see
84 shortly. You'll have to know something about those "ASCII" platforms
85 because the documentation is biased and will frequently use example
86 numbers that don't apply to EBCDIC. There are also very few CPAN
87 modules that are written for EBCDIC and which don't work on ASCII;
88 instead the vast majority of CPAN modules are written for ASCII, and
89 some may happen to work on EBCDIC, while a few have been designed to
90 portably work on both.
91 .PP
92 If your code just uses the 52 letters A\-Z and a\-z, plus SPACE, the
93 digits 0\-9, and the punctuation characters that Perl uses, plus a few
94 controls that are denoted by escape sequences like \f(CW\*(C`\en\*(C'\fR and \f(CW\*(C`\et\*(C'\fR, then
95 there's nothing special about using Perl, and your code may very well
96 work on an ASCII machine without change.
97 .PP
98 But if you write code that uses \f(CW\*(C`\e005\*(C'\fR to mean a TAB or \f(CW\*(C`\exC1\*(C'\fR to mean
99 an "A", or \f(CW\*(C`\exDF\*(C'\fR to mean a "ÿ" (small \f(CW"y"\fR with a diaeresis),
100 then your code may well work on your EBCDIC platform, but not on an
101 ASCII one. That's fine to do if no one will ever want to run your code
102 on an ASCII platform; but the bias in this document will be towards writing
103 code portable between EBCDIC and ASCII systems. Again, if every
104 character you care about is easily enterable from your keyboard, you
105 don't have to know anything about ASCII, but many keyboards don't easily
106 allow you to directly enter, say, the character \f(CW\*(C`\exDF\*(C'\fR, so you have to
107 specify it indirectly, such as by using the \f(CW"\exDF"\fR escape sequence.
108 In those cases it's easiest to know something about the ASCII/Unicode
109 character sets. If you know that the small "ÿ" is \f(CW\*(C`U+00FF\*(C'\fR, then
110 you can instead specify it as \f(CW"\eN{U+FF}"\fR, and have the computer
111 automatically translate it to \f(CW\*(C`\exDF\*(C'\fR on your platform, and leave it as
112 \&\f(CW\*(C`\exFF\*(C'\fR on ASCII ones. Or you could specify it by name, \f(CW\*(C`\eN{LATIN
113 SMALL LETTER Y WITH DIAERESIS\*(C'\fR and not have to know the numbers.
114 Either way works, but both require familiarity with Unicode.
115 .SH "COMMON CHARACTER CODE SETS"
116 .IX Header "COMMON CHARACTER CODE SETS"
117 .SS ASCII
118 .IX Subsection "ASCII"
119 The American Standard Code for Information Interchange (ASCII or
120 US-ASCII) is a set of
121 integers running from 0 to 127 (decimal) that have standardized
122 interpretations by the computers which use ASCII. For example, 65 means
123 the letter "A".
124 The range 0..127 can be covered by setting various bits in a 7\-bit binary
125 digit, hence the set is sometimes referred to as "7\-bit ASCII".
126 ASCII was described by the American National Standards Institute
127 document ANSI X3.4\-1986. It was also described by ISO 646:1991
128 (with localization for currency symbols). The full ASCII set is
129 given in the table below as the first 128 elements.
130 Languages that
131 can be written adequately with the characters in ASCII include
132 English, Hawaiian, Indonesian, Swahili and some Native American
133 languages.
134 .PP
135 Most non-EBCDIC character sets are supersets of ASCII. That is the
136 integers 0\-127 mean what ASCII says they mean. But integers 128 and
137 above are specific to the character set.
138 .PP
139 Many of these fit entirely into 8 bits, using ASCII as 0\-127, while
140 specifying what 128\-255 mean, and not using anything above 255.
141 Thus, these are single-byte (or octet if you prefer) character sets.
142 One important one (since Unicode is a superset of it) is the ISO 8859\-1
143 character set.
144 .SS "ISO 8859"
145 .IX Subsection "ISO 8859"
146 The ISO 8859\-\fR\f(CB$n\fR\f(BI\fR\fI\fR are a collection of character code sets from the
147 International Organization for Standardization (ISO), each of which adds
148 characters to the ASCII set that are typically found in various
149 languages, many of which are based on the Roman, or Latin, alphabet.
150 Most are for European languages, but there are also ones for Arabic,
151 Greek, Hebrew, and Thai. There are good references on the web about
152 all these.
153 .SS "Latin 1 (ISO 8859\-1)"
154 .IX Subsection "Latin 1 (ISO 8859-1)"
155 A particular 8\-bit extension to ASCII that includes grave and acute
156 accented Latin characters. Languages that can employ ISO 8859\-1
157 include all the languages covered by ASCII as well as Afrikaans,
158 Albanian, Basque, Catalan, Danish, Faroese, Finnish, Norwegian,
159 Portuguese, Spanish, and Swedish. Dutch is covered albeit without
160 the ij ligature. French is covered too but without the oe ligature.
161 German can use ISO 8859\-1 but must do so without German-style
162 quotation marks. This set is based on Western European extensions
163 to ASCII and is commonly encountered in world wide web work.
164 In IBM character code set identification terminology, ISO 8859\-1 is
165 also known as CCSID 819 (or sometimes 0819 or even 00819).
166 .SS EBCDIC
167 .IX Subsection "EBCDIC"
168 The Extended Binary Coded Decimal Interchange Code refers to a
169 large collection of single\- and multi-byte coded character sets that are
170 quite different from ASCII and ISO 8859\-1, and are all slightly
171 different from each other; they typically run on host computers. The
172 EBCDIC encodings derive from 8\-bit byte extensions of Hollerith punched
173 card encodings, which long predate ASCII. The layout on the
174 cards was such that high bits were set for the upper and lower case
175 alphabetic
176 characters \f(CW\*(C`[a\-z]\*(C'\fR and \f(CW\*(C`[A\-Z]\*(C'\fR, but there were gaps within each Latin
177 alphabet range, visible in the table below. These gaps can
178 cause complications.
179 .PP
180 Some IBM EBCDIC character sets may be known by character code set
181 identification numbers (CCSID numbers) or code page numbers.
182 .PP
183 Perl can be compiled on platforms that run any of three commonly used EBCDIC
184 character sets, listed below.
185 .PP
186 \fIThe 13 variant characters\fR
187 .IX Subsection "The 13 variant characters"
188 .PP
189 Among IBM EBCDIC character code sets there are 13 characters that
190 are often mapped to different integer values. Those characters
191 are known as the 13 "variant" characters and are:
192 .PP
193 .Vb 1
194 \& \e [ ] { } ^ ~ ! # | $ @ \`
195 .Ve
196 .PP
197 When Perl is compiled for a platform, it looks at all of these characters to
198 guess which EBCDIC character set the platform uses, and adapts itself
199 accordingly to that platform. If the platform uses a character set that is not
200 one of the three Perl knows about, Perl will either fail to compile, or
201 mistakenly and silently choose one of the three.
202 .PP
203 The Line Feed (LF) character is actually a 14th variant character, and
204 Perl checks for that as well.
205 .PP
206 \fIEBCDIC code sets recognized by Perl\fR
207 .IX Subsection "EBCDIC code sets recognized by Perl"
208 .IP \fB0037\fR 4
209 .IX Item "0037"
210 Character code set ID 0037 is a mapping of the ASCII plus Latin\-1
211 characters (i.e. ISO 8859\-1) to an EBCDIC set. 0037 is used
212 in North American English locales on the OS/400 operating system
213 that runs on AS/400 computers. CCSID 0037 differs from ISO 8859\-1
214 in 236 places; in other words they agree on only 20 code point values.
215 .IP \fB1047\fR 4
216 .IX Item "1047"
217 Character code set ID 1047 is also a mapping of the ASCII plus
218 Latin\-1 characters (i.e. ISO 8859\-1) to an EBCDIC set. 1047 is
219 used under Unix System Services for OS/390 or z/OS, and OpenEdition
220 for VM/ESA. CCSID 1047 differs from CCSID 0037 in eight places,
221 and from ISO 8859\-1 in 236.
222 .IP \fBPOSIX-BC\fR 4
223 .IX Item "POSIX-BC"
224 The EBCDIC code page in use on Siemens' BS2000 system is distinct from
225 1047 and 0037. It is identified below as the POSIX-BC set.
226 Like 0037 and 1047, it is the same as ISO 8859\-1 in 20 code point
227 values.
228 .SS "Unicode code points versus EBCDIC code points"
229 .IX Subsection "Unicode code points versus EBCDIC code points"
230 In Unicode terminology a \fIcode point\fR is the number assigned to a
231 character: for example, in EBCDIC the character "A" is usually assigned
232 the number 193. In Unicode, the character "A" is assigned the number 65.
233 All the code points in ASCII and Latin\-1 (ISO 8859\-1) have the same
234 meaning in Unicode. All three of the recognized EBCDIC code sets have
235 256 code points, and in each code set, all 256 code points are mapped to
236 equivalent Latin1 code points. Obviously, "A" will map to "A", "B" =>
237 "B", "%" => "%", etc., for all printable characters in Latin1 and these
238 code pages.
239 .PP
240 It also turns out that EBCDIC has nearly precise equivalents for the
241 ASCII/Latin1 C0 controls and the DELETE control. (The C0 controls are
242 those whose ASCII code points are 0..0x1F; things like TAB, ACK, BEL,
243 etc.) A mapping is set up between these ASCII/EBCDIC controls. There
244 isn't such a precise mapping between the C1 controls on ASCII platforms
245 and the remaining EBCDIC controls. What has been done is to map these
246 controls, mostly arbitrarily, to some otherwise unmatched character in
247 the other character set. Most of these are very very rarely used
248 nowadays in EBCDIC anyway, and their names have been dropped, without
249 much complaint. For example the EO (Eight Ones) EBCDIC control
250 (consisting of eight one bits = 0xFF) is mapped to the C1 APC control
251 (0x9F), and you can't use the name "EO".
252 .PP
253 The EBCDIC controls provide three possible line terminator characters,
254 CR (0x0D), LF (0x25), and NL (0x15). On ASCII platforms, the symbols
255 "NL" and "LF" refer to the same character, but in strict EBCDIC
256 terminology they are different ones. The EBCDIC NL is mapped to the C1
257 control called "NEL" ("Next Line"; here's a case where the mapping makes
258 quite a bit of sense, and hence isn't just arbitrary). On some EBCDIC
259 platforms, this NL or NEL is the typical line terminator. This is true
260 of z/OS and BS2000. In these platforms, the C compilers will swap the
261 LF and NEL code points, so that \f(CW"\en"\fR is 0x15, and refers to NL. Perl
262 does that too; you can see it in the code chart below.
263 This makes things generally "just work" without you even having to be
264 aware that there is a swap.
265 .SS "Unicode and UTF"
266 .IX Subsection "Unicode and UTF"
267 UTF stands for "Unicode Transformation Format".
268 UTF\-8 is an encoding of Unicode into a sequence of 8\-bit byte chunks, based on
269 ASCII and Latin\-1.
270 The length of a sequence required to represent a Unicode code point
271 depends on the ordinal number of that code point,
272 with larger numbers requiring more bytes.
273 UTF-EBCDIC is like UTF\-8, but based on EBCDIC.
274 They are enough alike that often, casual usage will conflate the two
275 terms, and use "UTF\-8" to mean both the UTF\-8 found on ASCII platforms,
276 and the UTF-EBCDIC found on EBCDIC ones.
277 .PP
278 You may see the term "invariant" character or code point.
279 This simply means that the character has the same numeric
280 value and representation when encoded in UTF\-8 (or UTF-EBCDIC) as when
281 not. (Note that this is a very different concept from "The 13 variant
282 characters" mentioned above. Careful prose will use the term "UTF\-8
283 invariant" instead of just "invariant", but most often you'll see just
284 "invariant".) For example, the ordinal value of "A" is 193 in most
285 EBCDIC code pages, and also is 193 when encoded in UTF-EBCDIC. All
286 UTF\-8 (or UTF-EBCDIC) variant code points occupy at least two bytes when
287 encoded in UTF\-8 (or UTF-EBCDIC); by definition, the UTF\-8 (or
288 UTF-EBCDIC) invariant code points are exactly one byte whether encoded
289 in UTF\-8 (or UTF-EBCDIC), or not. (By now you see why people typically
290 just say "UTF\-8" when they also mean "UTF-EBCDIC". For the rest of this
291 document, we'll mostly be casual about it too.)
292 In ASCII UTF\-8, the code points corresponding to the lowest 128
293 ordinal numbers (0 \- 127: the ASCII characters) are invariant.
294 In UTF-EBCDIC, there are 160 invariant characters.
295 (If you care, the EBCDIC invariants are those characters
296 which have ASCII equivalents, plus those that correspond to
297 the C1 controls (128 \- 159 on ASCII platforms).)
298 .PP
299 A string encoded in UTF-EBCDIC may be longer (very rarely shorter) than
300 one encoded in UTF\-8. Perl extends both UTF\-8 and UTF-EBCDIC so that
301 they can encode code points above the Unicode maximum of U+10FFFF. Both
302 extensions are constructed to allow encoding of any code point that fits
303 in a 64\-bit word.
304 .PP
305 UTF-EBCDIC is defined by
306 Unicode Technical Report #16 <https://www.unicode.org/reports/tr16>
307 (often referred to as just TR16).
308 It is defined based on CCSID 1047, not allowing for the differences for
309 other code pages. This allows for easy interchange of text between
310 computers running different code pages, but makes it unusable, without
311 adaptation, for Perl on those other code pages.
312 .PP
313 The reason for this unusability is that a fundamental assumption of Perl
314 is that the characters it cares about for parsing and lexical analysis
315 are the same whether or not the text is in UTF\-8. For example, Perl
316 expects the character \f(CW"["\fR to have the same representation, no matter
317 if the string containing it (or program text) is UTF\-8 encoded or not.
318 To ensure this, Perl adapts UTF-EBCDIC to the particular code page so
319 that all characters it expects to be UTF\-8 invariant are in fact UTF\-8
320 invariant. This means that text generated on a computer running one
321 version of Perl's UTF-EBCDIC has to be translated to be intelligible to
322 a computer running another.
323 .PP
324 TR16 implies a method to extend UTF-EBCDIC to encode points up through
325 \&\f(CW\*(C`2\ **\ 31\ \-\ 1\*(C'\fR. Perl uses this method for code points up through
326 \&\f(CW\*(C`2\ **\ 30\ \-\ 1\*(C'\fR, but uses an incompatible method for larger ones, to
327 enable it to handle much larger code points than otherwise.
328 .SS "Using Encode"
329 .IX Subsection "Using Encode"
330 Starting from Perl 5.8 you can use the standard module Encode
331 to translate from EBCDIC to Latin\-1 code points.
332 Encode knows about more EBCDIC character sets than Perl can currently
333 be compiled to run on.
334 .PP
335 .Vb 1
336 \& use Encode \*(Aqfrom_to\*(Aq;
337 \&
338 \& my %ebcdic = ( 176 => \*(Aqcp37\*(Aq, 95 => \*(Aqcp1047\*(Aq, 106 => \*(Aqposix\-bc\*(Aq );
339 \&
340 \& # $x is in EBCDIC code points
341 \& from_to($x, $ebcdic{ord \*(Aq^\*(Aq}, \*(Aqlatin1\*(Aq);
342 \& # $x is ISO 8859\-1 code points
343 .Ve
344 .PP
345 and from Latin\-1 code points to EBCDIC code points
346 .PP
347 .Vb 1
348 \& use Encode \*(Aqfrom_to\*(Aq;
349 \&
350 \& my %ebcdic = ( 176 => \*(Aqcp37\*(Aq, 95 => \*(Aqcp1047\*(Aq, 106 => \*(Aqposix\-bc\*(Aq );
351 \&
352 \& # $x is ISO 8859\-1 code points
353 \& from_to($x, \*(Aqlatin1\*(Aq, $ebcdic{ord \*(Aq^\*(Aq});
354 \& # $x is in EBCDIC code points
355 .Ve
356 .PP
357 For doing I/O it is suggested that you use the autotranslating features
358 of PerlIO, see perluniintro.
359 .PP
360 Since version 5.8 Perl uses the PerlIO I/O library. This enables
361 you to use different encodings per IO channel. For example you may use
362 .PP
363 .Vb 9
364 \& use Encode;
365 \& open($f, ">:encoding(ascii)", "test.ascii");
366 \& print $f "Hello World!\en";
367 \& open($f, ">:encoding(cp37)", "test.ebcdic");
368 \& print $f "Hello World!\en";
369 \& open($f, ">:encoding(latin1)", "test.latin1");
370 \& print $f "Hello World!\en";
371 \& open($f, ">:encoding(utf8)", "test.utf8");
372 \& print $f "Hello World!\en";
373 .Ve
374 .PP
375 to get four files containing "Hello World!\en" in ASCII, CP 0037 EBCDIC,
376 ISO 8859\-1 (Latin\-1) (in this example identical to ASCII since only ASCII
377 characters were printed), and
378 UTF-EBCDIC (in this example identical to normal EBCDIC since only characters
379 that don't differ between EBCDIC and UTF-EBCDIC were printed). See the
380 documentation of Encode::PerlIO for details.
381 .PP
382 As the PerlIO layer uses raw IO (bytes) internally, all this totally
383 ignores things like the type of your filesystem (ASCII or EBCDIC).
384 .SH "SINGLE OCTET TABLES"
385 .IX Header "SINGLE OCTET TABLES"
386 The following tables list the ASCII and Latin 1 ordered sets including
387 the subsets: C0 controls (0..31), ASCII graphics (32..7e), delete (7f),
388 C1 controls (80..9f), and Latin\-1 (a.k.a. ISO 8859\-1) (a0..ff). In the
389 table names of the Latin 1
390 extensions to ASCII have been labelled with character names roughly
391 corresponding to \fIThe Unicode Standard, Version 6.1\fR albeit with
392 substitutions such as \f(CW\*(C`s/LATIN//\*(C'\fR and \f(CW\*(C`s/VULGAR//\*(C'\fR in all cases;
393 \&\f(CW\*(C`s/CAPITAL\ LETTER//\*(C'\fR in some cases; and
394 \&\f(CW\*(C`s/SMALL\ LETTER\ ([A\-Z])/\el$1/\*(C'\fR in some other
395 cases. Controls are listed using their Unicode 6.2 abbreviations.
396 The differences between the 0037 and 1047 sets are
397 flagged with \f(CW\*(C`**\*(C'\fR. The differences between the 1047 and POSIX-BC sets
398 are flagged with \f(CW\*(C`##.\*(C'\fR All \f(CWord()\fR numbers listed are decimal. If you
399 would rather see this table listing octal values, then run the table
400 (that is, the pod source text of this document, since this recipe may not
401 work with a pod2_other_format translation) through:
402 .IP "recipe 0" 4
403 .IX Item "recipe 0"
404 .PP
405 .Vb 3
406 \& perl \-ne \*(Aqif(/(.{29})(\ed+)\es+(\ed+)\es+(\ed+)\es+(\ed+)/)\*(Aq \e
407 \& \-e \*(Aq{printf("%s%\-5.03o%\-5.03o%\-5.03o%.03o\en",$1,$2,$3,$4,$5)}\*(Aq \e
408 \& perlebcdic.pod
409 .Ve
410 .PP
411 If you want to retain the UTF-x code points then in script form you
412 might want to write:
413 .IP "recipe 1" 4
414 .IX Item "recipe 1"
415 .PP
416 .Vb 10
417 \& open(FH,"<perlebcdic.pod") or die "Could not open perlebcdic.pod: $!";
418 \& while (<FH>) {
419 \& if (/(.{29})(\ed+)\es+(\ed+)\es+(\ed+)\es+(\ed+)\es+(\ed+)\e.?(\ed*)
420 \& \es+(\ed+)\e.?(\ed*)/x)
421 \& {
422 \& if ($7 ne \*(Aq\*(Aq && $9 ne \*(Aq\*(Aq) {
423 \& printf(
424 \& "%s%\-5.03o%\-5.03o%\-5.03o%\-5.03o%\-3o.%\-5o%\-3o.%.03o\en",
425 \& $1,$2,$3,$4,$5,$6,$7,$8,$9);
426 \& }
427 \& elsif ($7 ne \*(Aq\*(Aq) {
428 \& printf("%s%\-5.03o%\-5.03o%\-5.03o%\-5.03o%\-3o.%\-5o%.03o\en",
429 \& $1,$2,$3,$4,$5,$6,$7,$8);
430 \& }
431 \& else {
432 \& printf("%s%\-5.03o%\-5.03o%\-5.03o%\-5.03o%\-5.03o%.03o\en",
433 \& $1,$2,$3,$4,$5,$6,$8);
434 \& }
435 \& }
436 \& }
437 .Ve
438 .PP
439 If you would rather see this table listing hexadecimal values then
440 run the table through:
441 .IP "recipe 2" 4
442 .IX Item "recipe 2"
443 .PP
444 .Vb 3
445 \& perl \-ne \*(Aqif(/(.{29})(\ed+)\es+(\ed+)\es+(\ed+)\es+(\ed+)/)\*(Aq \e
446 \& \-e \*(Aq{printf("%s%\-5.02X%\-5.02X%\-5.02X%.02X\en",$1,$2,$3,$4,$5)}\*(Aq \e
447 \& perlebcdic.pod
448 .Ve
449 .PP
450 Or, in order to retain the UTF-x code points in hexadecimal:
451 .IP "recipe 3" 4
452 .IX Item "recipe 3"
453 .PP
454 .Vb 10
455 \& open(FH,"<perlebcdic.pod") or die "Could not open perlebcdic.pod: $!";
456 \& while (<FH>) {
457 \& if (/(.{29})(\ed+)\es+(\ed+)\es+(\ed+)\es+(\ed+)\es+(\ed+)\e.?(\ed*)
458 \& \es+(\ed+)\e.?(\ed*)/x)
459 \& {
460 \& if ($7 ne \*(Aq\*(Aq && $9 ne \*(Aq\*(Aq) {
461 \& printf(
462 \& "%s%\-5.02X%\-5.02X%\-5.02X%\-5.02X%\-2X.%\-6.02X%02X.%02X\en",
463 \& $1,$2,$3,$4,$5,$6,$7,$8,$9);
464 \& }
465 \& elsif ($7 ne \*(Aq\*(Aq) {
466 \& printf("%s%\-5.02X%\-5.02X%\-5.02X%\-5.02X%\-2X.%\-6.02X%02X\en",
467 \& $1,$2,$3,$4,$5,$6,$7,$8);
468 \& }
469 \& else {
470 \& printf("%s%\-5.02X%\-5.02X%\-5.02X%\-5.02X%\-5.02X%02X\en",
471 \& $1,$2,$3,$4,$5,$6,$8);
472 \& }
473 \& }
474 \& }
475 \&
476 \&
477 \& ISO
478 \& 8859\-1 POS\- CCSID
479 \& CCSID CCSID CCSID IX\- 1047
480 \& chr 0819 0037 1047 BC UTF\-8 UTF\-EBCDIC
481 \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
482 \& <NUL> 0 0 0 0 0 0
483 \& <SOH> 1 1 1 1 1 1
484 \& <STX> 2 2 2 2 2 2
485 \& <ETX> 3 3 3 3 3 3
486 \& <EOT> 4 55 55 55 4 55
487 \& <ENQ> 5 45 45 45 5 45
488 \& <ACK> 6 46 46 46 6 46
489 \& <BEL> 7 47 47 47 7 47
490 \& <BS> 8 22 22 22 8 22
491 \& <HT> 9 5 5 5 9 5
492 \& <LF> 10 37 21 21 10 21 **
493 \& <VT> 11 11 11 11 11 11
494 \& <FF> 12 12 12 12 12 12
495 \& <CR> 13 13 13 13 13 13
496 \& <SO> 14 14 14 14 14 14
497 \& <SI> 15 15 15 15 15 15
498 \& <DLE> 16 16 16 16 16 16
499 \& <DC1> 17 17 17 17 17 17
500 \& <DC2> 18 18 18 18 18 18
501 \& <DC3> 19 19 19 19 19 19
502 \& <DC4> 20 60 60 60 20 60
503 \& <NAK> 21 61 61 61 21 61
504 \& <SYN> 22 50 50 50 22 50
505 \& <ETB> 23 38 38 38 23 38
506 \& <CAN> 24 24 24 24 24 24
507 \& <EOM> 25 25 25 25 25 25
508 \& <SUB> 26 63 63 63 26 63
509 \& <ESC> 27 39 39 39 27 39
510 \& <FS> 28 28 28 28 28 28
511 \& <GS> 29 29 29 29 29 29
512 \& <RS> 30 30 30 30 30 30
513 \& <US> 31 31 31 31 31 31
514 \& <SPACE> 32 64 64 64 32 64
515 \& ! 33 90 90 90 33 90
516 \& " 34 127 127 127 34 127
517 \& # 35 123 123 123 35 123
518 \& $ 36 91 91 91 36 91
519 \& % 37 108 108 108 37 108
520 \& & 38 80 80 80 38 80
521 \& \*(Aq 39 125 125 125 39 125
522 \& ( 40 77 77 77 40 77
523 \& ) 41 93 93 93 41 93
524 \& * 42 92 92 92 42 92
525 \& + 43 78 78 78 43 78
526 \& , 44 107 107 107 44 107
527 \& \- 45 96 96 96 45 96
528 \& . 46 75 75 75 46 75
529 \& / 47 97 97 97 47 97
530 \& 0 48 240 240 240 48 240
531 \& 1 49 241 241 241 49 241
532 \& 2 50 242 242 242 50 242
533 \& 3 51 243 243 243 51 243
534 \& 4 52 244 244 244 52 244
535 \& 5 53 245 245 245 53 245
536 \& 6 54 246 246 246 54 246
537 \& 7 55 247 247 247 55 247
538 \& 8 56 248 248 248 56 248
539 \& 9 57 249 249 249 57 249
540 \& : 58 122 122 122 58 122
541 \& ; 59 94 94 94 59 94
542 \& < 60 76 76 76 60 76
543 \& = 61 126 126 126 61 126
544 \& > 62 110 110 110 62 110
545 \& ? 63 111 111 111 63 111
546 \& @ 64 124 124 124 64 124
547 \& A 65 193 193 193 65 193
548 \& B 66 194 194 194 66 194
549 \& C 67 195 195 195 67 195
550 \& D 68 196 196 196 68 196
551 \& E 69 197 197 197 69 197
552 \& F 70 198 198 198 70 198
553 \& G 71 199 199 199 71 199
554 \& H 72 200 200 200 72 200
555 \& I 73 201 201 201 73 201
556 \& J 74 209 209 209 74 209
557 \& K 75 210 210 210 75 210
558 \& L 76 211 211 211 76 211
559 \& M 77 212 212 212 77 212
560 \& N 78 213 213 213 78 213
561 \& O 79 214 214 214 79 214
562 \& P 80 215 215 215 80 215
563 \& Q 81 216 216 216 81 216
564 \& R 82 217 217 217 82 217
565 \& S 83 226 226 226 83 226
566 \& T 84 227 227 227 84 227
567 \& U 85 228 228 228 85 228
568 \& V 86 229 229 229 86 229
569 \& W 87 230 230 230 87 230
570 \& X 88 231 231 231 88 231
571 \& Y 89 232 232 232 89 232
572 \& Z 90 233 233 233 90 233
573 \& [ 91 186 173 187 91 173 ** ##
574 \& \e 92 224 224 188 92 224 ##
575 \& ] 93 187 189 189 93 189 **
576 \& ^ 94 176 95 106 94 95 ** ##
577 \& _ 95 109 109 109 95 109
578 \& \` 96 121 121 74 96 121 ##
579 \& a 97 129 129 129 97 129
580 \& b 98 130 130 130 98 130
581 \& c 99 131 131 131 99 131
582 \& d 100 132 132 132 100 132
583 \& e 101 133 133 133 101 133
584 \& f 102 134 134 134 102 134
585 \& g 103 135 135 135 103 135
586 \& h 104 136 136 136 104 136
587 \& i 105 137 137 137 105 137
588 \& j 106 145 145 145 106 145
589 \& k 107 146 146 146 107 146
590 \& l 108 147 147 147 108 147
591 \& m 109 148 148 148 109 148
592 \& n 110 149 149 149 110 149
593 \& o 111 150 150 150 111 150
594 \& p 112 151 151 151 112 151
595 \& q 113 152 152 152 113 152
596 \& r 114 153 153 153 114 153
597 \& s 115 162 162 162 115 162
598 \& t 116 163 163 163 116 163
599 \& u 117 164 164 164 117 164
600 \& v 118 165 165 165 118 165
601 \& w 119 166 166 166 119 166
602 \& x 120 167 167 167 120 167
603 \& y 121 168 168 168 121 168
604 \& z 122 169 169 169 122 169
605 \& { 123 192 192 251 123 192 ##
606 \& | 124 79 79 79 124 79
607 \& } 125 208 208 253 125 208 ##
608 \& ~ 126 161 161 255 126 161 ##
609 \& <DEL> 127 7 7 7 127 7
610 \& <PAD> 128 32 32 32 194.128 32
611 \& <HOP> 129 33 33 33 194.129 33
612 \& <BPH> 130 34 34 34 194.130 34
613 \& <NBH> 131 35 35 35 194.131 35
614 \& <IND> 132 36 36 36 194.132 36
615 \& <NEL> 133 21 37 37 194.133 37 **
616 \& <SSA> 134 6 6 6 194.134 6
617 \& <ESA> 135 23 23 23 194.135 23
618 \& <HTS> 136 40 40 40 194.136 40
619 \& <HTJ> 137 41 41 41 194.137 41
620 \& <VTS> 138 42 42 42 194.138 42
621 \& <PLD> 139 43 43 43 194.139 43
622 \& <PLU> 140 44 44 44 194.140 44
623 \& <RI> 141 9 9 9 194.141 9
624 \& <SS2> 142 10 10 10 194.142 10
625 \& <SS3> 143 27 27 27 194.143 27
626 \& <DCS> 144 48 48 48 194.144 48
627 \& <PU1> 145 49 49 49 194.145 49
628 \& <PU2> 146 26 26 26 194.146 26
629 \& <STS> 147 51 51 51 194.147 51
630 \& <CCH> 148 52 52 52 194.148 52
631 \& <MW> 149 53 53 53 194.149 53
632 \& <SPA> 150 54 54 54 194.150 54
633 \& <EPA> 151 8 8 8 194.151 8
634 \& <SOS> 152 56 56 56 194.152 56
635 \& <SGC> 153 57 57 57 194.153 57
636 \& <SCI> 154 58 58 58 194.154 58
637 \& <CSI> 155 59 59 59 194.155 59
638 \& <ST> 156 4 4 4 194.156 4
639 \& <OSC> 157 20 20 20 194.157 20
640 \& <PM> 158 62 62 62 194.158 62
641 \& <APC> 159 255 255 95 194.159 255 ##
642 \& <NON\-BREAKING SPACE> 160 65 65 65 194.160 128.65
643 \& <INVERTED "!" > 161 170 170 170 194.161 128.66
644 \& <CENT SIGN> 162 74 74 176 194.162 128.67 ##
645 \& <POUND SIGN> 163 177 177 177 194.163 128.68
646 \& <CURRENCY SIGN> 164 159 159 159 194.164 128.69
647 \& <YEN SIGN> 165 178 178 178 194.165 128.70
648 \& <BROKEN BAR> 166 106 106 208 194.166 128.71 ##
649 \& <SECTION SIGN> 167 181 181 181 194.167 128.72
650 \& <DIAERESIS> 168 189 187 121 194.168 128.73 ** ##
651 \& <COPYRIGHT SIGN> 169 180 180 180 194.169 128.74
652 \& <FEMININE ORDINAL> 170 154 154 154 194.170 128.81
653 \& <LEFT POINTING GUILLEMET> 171 138 138 138 194.171 128.82
654 \& <NOT SIGN> 172 95 176 186 194.172 128.83 ** ##
655 \& <SOFT HYPHEN> 173 202 202 202 194.173 128.84
656 \& <REGISTERED TRADE MARK> 174 175 175 175 194.174 128.85
657 \& <MACRON> 175 188 188 161 194.175 128.86 ##
658 \& <DEGREE SIGN> 176 144 144 144 194.176 128.87
659 \& <PLUS\-OR\-MINUS SIGN> 177 143 143 143 194.177 128.88
660 \& <SUPERSCRIPT TWO> 178 234 234 234 194.178 128.89
661 \& <SUPERSCRIPT THREE> 179 250 250 250 194.179 128.98
662 \& <ACUTE ACCENT> 180 190 190 190 194.180 128.99
663 \& <MICRO SIGN> 181 160 160 160 194.181 128.100
664 \& <PARAGRAPH SIGN> 182 182 182 182 194.182 128.101
665 \& <MIDDLE DOT> 183 179 179 179 194.183 128.102
666 \& <CEDILLA> 184 157 157 157 194.184 128.103
667 \& <SUPERSCRIPT ONE> 185 218 218 218 194.185 128.104
668 \& <MASC. ORDINAL INDICATOR> 186 155 155 155 194.186 128.105
669 \& <RIGHT POINTING GUILLEMET> 187 139 139 139 194.187 128.106
670 \& <FRACTION ONE QUARTER> 188 183 183 183 194.188 128.112
671 \& <FRACTION ONE HALF> 189 184 184 184 194.189 128.113
672 \& <FRACTION THREE QUARTERS> 190 185 185 185 194.190 128.114
673 \& <INVERTED QUESTION MARK> 191 171 171 171 194.191 128.115
674 \& <A WITH GRAVE> 192 100 100 100 195.128 138.65
675 \& <A WITH ACUTE> 193 101 101 101 195.129 138.66
676 \& <A WITH CIRCUMFLEX> 194 98 98 98 195.130 138.67
677 \& <A WITH TILDE> 195 102 102 102 195.131 138.68
678 \& <A WITH DIAERESIS> 196 99 99 99 195.132 138.69
679 \& <A WITH RING ABOVE> 197 103 103 103 195.133 138.70
680 \& <CAPITAL LIGATURE AE> 198 158 158 158 195.134 138.71
681 \& <C WITH CEDILLA> 199 104 104 104 195.135 138.72
682 \& <E WITH GRAVE> 200 116 116 116 195.136 138.73
683 \& <E WITH ACUTE> 201 113 113 113 195.137 138.74
684 \& <E WITH CIRCUMFLEX> 202 114 114 114 195.138 138.81
685 \& <E WITH DIAERESIS> 203 115 115 115 195.139 138.82
686 \& <I WITH GRAVE> 204 120 120 120 195.140 138.83
687 \& <I WITH ACUTE> 205 117 117 117 195.141 138.84
688 \& <I WITH CIRCUMFLEX> 206 118 118 118 195.142 138.85
689 \& <I WITH DIAERESIS> 207 119 119 119 195.143 138.86
690 \& <CAPITAL LETTER ETH> 208 172 172 172 195.144 138.87
691 \& <N WITH TILDE> 209 105 105 105 195.145 138.88
692 \& <O WITH GRAVE> 210 237 237 237 195.146 138.89
693 \& <O WITH ACUTE> 211 238 238 238 195.147 138.98
694 \& <O WITH CIRCUMFLEX> 212 235 235 235 195.148 138.99
695 \& <O WITH TILDE> 213 239 239 239 195.149 138.100
696 \& <O WITH DIAERESIS> 214 236 236 236 195.150 138.101
697 \& <MULTIPLICATION SIGN> 215 191 191 191 195.151 138.102
698 \& <O WITH STROKE> 216 128 128 128 195.152 138.103
699 \& <U WITH GRAVE> 217 253 253 224 195.153 138.104 ##
700 \& <U WITH ACUTE> 218 254 254 254 195.154 138.105
701 \& <U WITH CIRCUMFLEX> 219 251 251 221 195.155 138.106 ##
702 \& <U WITH DIAERESIS> 220 252 252 252 195.156 138.112
703 \& <Y WITH ACUTE> 221 173 186 173 195.157 138.113 ** ##
704 \& <CAPITAL LETTER THORN> 222 174 174 174 195.158 138.114
705 \& <SMALL LETTER SHARP S> 223 89 89 89 195.159 138.115
706 \& <a WITH GRAVE> 224 68 68 68 195.160 139.65
707 \& <a WITH ACUTE> 225 69 69 69 195.161 139.66
708 \& <a WITH CIRCUMFLEX> 226 66 66 66 195.162 139.67
709 \& <a WITH TILDE> 227 70 70 70 195.163 139.68
710 \& <a WITH DIAERESIS> 228 67 67 67 195.164 139.69
711 \& <a WITH RING ABOVE> 229 71 71 71 195.165 139.70
712 \& <SMALL LIGATURE ae> 230 156 156 156 195.166 139.71
713 \& <c WITH CEDILLA> 231 72 72 72 195.167 139.72
714 \& <e WITH GRAVE> 232 84 84 84 195.168 139.73
715 \& <e WITH ACUTE> 233 81 81 81 195.169 139.74
716 \& <e WITH CIRCUMFLEX> 234 82 82 82 195.170 139.81
717 \& <e WITH DIAERESIS> 235 83 83 83 195.171 139.82
718 \& <i WITH GRAVE> 236 88 88 88 195.172 139.83
719 \& <i WITH ACUTE> 237 85 85 85 195.173 139.84
720 \& <i WITH CIRCUMFLEX> 238 86 86 86 195.174 139.85
721 \& <i WITH DIAERESIS> 239 87 87 87 195.175 139.86
722 \& <SMALL LETTER eth> 240 140 140 140 195.176 139.87
723 \& <n WITH TILDE> 241 73 73 73 195.177 139.88
724 \& <o WITH GRAVE> 242 205 205 205 195.178 139.89
725 \& <o WITH ACUTE> 243 206 206 206 195.179 139.98
726 \& <o WITH CIRCUMFLEX> 244 203 203 203 195.180 139.99
727 \& <o WITH TILDE> 245 207 207 207 195.181 139.100
728 \& <o WITH DIAERESIS> 246 204 204 204 195.182 139.101
729 \& <DIVISION SIGN> 247 225 225 225 195.183 139.102
730 \& <o WITH STROKE> 248 112 112 112 195.184 139.103
731 \& <u WITH GRAVE> 249 221 221 192 195.185 139.104 ##
732 \& <u WITH ACUTE> 250 222 222 222 195.186 139.105
733 \& <u WITH CIRCUMFLEX> 251 219 219 219 195.187 139.106
734 \& <u WITH DIAERESIS> 252 220 220 220 195.188 139.112
735 \& <y WITH ACUTE> 253 141 141 141 195.189 139.113
736 \& <SMALL LETTER thorn> 254 142 142 142 195.190 139.114
737 \& <y WITH DIAERESIS> 255 223 223 223 195.191 139.115
738 .Ve
739 .PP
740 If you would rather see the above table in CCSID 0037 order rather than
741 ASCII + Latin\-1 order then run the table through:
742 .IP "recipe 4" 4
743 .IX Item "recipe 4"
744 .PP
745 .Vb 6
746 \& perl \e
747 \& \-ne \*(Aqif(/.{29}\ed{1,3}\es{2,4}\ed{1,3}\es{2,4}\ed{1,3}\es{2,4}\ed{1,3}/)\*(Aq\e
748 \& \-e \*(Aq{push(@l,$_)}\*(Aq \e
749 \& \-e \*(AqEND{print map{$_\->[0]}\*(Aq \e
750 \& \-e \*(Aq sort{$a\->[1] <=> $b\->[1]}\*(Aq \e
751 \& \-e \*(Aq map{[$_,substr($_,34,3)]}@l;}\*(Aq perlebcdic.pod
752 .Ve
753 .PP
754 If you would rather see it in CCSID 1047 order then change the number
755 34 in the last line to 39, like this:
756 .IP "recipe 5" 4
757 .IX Item "recipe 5"
758 .PP
759 .Vb 6
760 \& perl \e
761 \& \-ne \*(Aqif(/.{29}\ed{1,3}\es{2,4}\ed{1,3}\es{2,4}\ed{1,3}\es{2,4}\ed{1,3}/)\*(Aq\e
762 \& \-e \*(Aq{push(@l,$_)}\*(Aq \e
763 \& \-e \*(AqEND{print map{$_\->[0]}\*(Aq \e
764 \& \-e \*(Aq sort{$a\->[1] <=> $b\->[1]}\*(Aq \e
765 \& \-e \*(Aq map{[$_,substr($_,39,3)]}@l;}\*(Aq perlebcdic.pod
766 .Ve
767 .PP
768 If you would rather see it in POSIX-BC order then change the number
769 34 in the last line to 44, like this:
770 .IP "recipe 6" 4
771 .IX Item "recipe 6"
772 .PP
773 .Vb 6
774 \& perl \e
775 \& \-ne \*(Aqif(/.{29}\ed{1,3}\es{2,4}\ed{1,3}\es{2,4}\ed{1,3}\es{2,4}\ed{1,3}/)\*(Aq\e
776 \& \-e \*(Aq{push(@l,$_)}\*(Aq \e
777 \& \-e \*(AqEND{print map{$_\->[0]}\*(Aq \e
778 \& \-e \*(Aq sort{$a\->[1] <=> $b\->[1]}\*(Aq \e
779 \& \-e \*(Aq map{[$_,substr($_,44,3)]}@l;}\*(Aq perlebcdic.pod
780 .Ve
781 .SS "Table in hex, sorted in 1047 order"
782 .IX Subsection "Table in hex, sorted in 1047 order"
783 Since this document was first written, the convention has become more
784 and more to use hexadecimal notation for code points. To do this with
785 the recipes and to also sort is a multi-step process, so here, for
786 convenience, is the table from above, re-sorted to be in Code Page 1047
787 order, and using hex notation.
788 .PP
789 .Vb 10
790 \& ISO
791 \& 8859\-1 POS\- CCSID
792 \& CCSID CCSID CCSID IX\- 1047
793 \& chr 0819 0037 1047 BC UTF\-8 UTF\-EBCDIC
794 \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
795 \& <NUL> 00 00 00 00 00 00
796 \& <SOH> 01 01 01 01 01 01
797 \& <STX> 02 02 02 02 02 02
798 \& <ETX> 03 03 03 03 03 03
799 \& <ST> 9C 04 04 04 C2.9C 04
800 \& <HT> 09 05 05 05 09 05
801 \& <SSA> 86 06 06 06 C2.86 06
802 \& <DEL> 7F 07 07 07 7F 07
803 \& <EPA> 97 08 08 08 C2.97 08
804 \& <RI> 8D 09 09 09 C2.8D 09
805 \& <SS2> 8E 0A 0A 0A C2.8E 0A
806 \& <VT> 0B 0B 0B 0B 0B 0B
807 \& <FF> 0C 0C 0C 0C 0C 0C
808 \& <CR> 0D 0D 0D 0D 0D 0D
809 \& <SO> 0E 0E 0E 0E 0E 0E
810 \& <SI> 0F 0F 0F 0F 0F 0F
811 \& <DLE> 10 10 10 10 10 10
812 \& <DC1> 11 11 11 11 11 11
813 \& <DC2> 12 12 12 12 12 12
814 \& <DC3> 13 13 13 13 13 13
815 \& <OSC> 9D 14 14 14 C2.9D 14
816 \& <LF> 0A 25 15 15 0A 15 **
817 \& <BS> 08 16 16 16 08 16
818 \& <ESA> 87 17 17 17 C2.87 17
819 \& <CAN> 18 18 18 18 18 18
820 \& <EOM> 19 19 19 19 19 19
821 \& <PU2> 92 1A 1A 1A C2.92 1A
822 \& <SS3> 8F 1B 1B 1B C2.8F 1B
823 \& <FS> 1C 1C 1C 1C 1C 1C
824 \& <GS> 1D 1D 1D 1D 1D 1D
825 \& <RS> 1E 1E 1E 1E 1E 1E
826 \& <US> 1F 1F 1F 1F 1F 1F
827 \& <PAD> 80 20 20 20 C2.80 20
828 \& <HOP> 81 21 21 21 C2.81 21
829 \& <BPH> 82 22 22 22 C2.82 22
830 \& <NBH> 83 23 23 23 C2.83 23
831 \& <IND> 84 24 24 24 C2.84 24
832 \& <NEL> 85 15 25 25 C2.85 25 **
833 \& <ETB> 17 26 26 26 17 26
834 \& <ESC> 1B 27 27 27 1B 27
835 \& <HTS> 88 28 28 28 C2.88 28
836 \& <HTJ> 89 29 29 29 C2.89 29
837 \& <VTS> 8A 2A 2A 2A C2.8A 2A
838 \& <PLD> 8B 2B 2B 2B C2.8B 2B
839 \& <PLU> 8C 2C 2C 2C C2.8C 2C
840 \& <ENQ> 05 2D 2D 2D 05 2D
841 \& <ACK> 06 2E 2E 2E 06 2E
842 \& <BEL> 07 2F 2F 2F 07 2F
843 \& <DCS> 90 30 30 30 C2.90 30
844 \& <PU1> 91 31 31 31 C2.91 31
845 \& <SYN> 16 32 32 32 16 32
846 \& <STS> 93 33 33 33 C2.93 33
847 \& <CCH> 94 34 34 34 C2.94 34
848 \& <MW> 95 35 35 35 C2.95 35
849 \& <SPA> 96 36 36 36 C2.96 36
850 \& <EOT> 04 37 37 37 04 37
851 \& <SOS> 98 38 38 38 C2.98 38
852 \& <SGC> 99 39 39 39 C2.99 39
853 \& <SCI> 9A 3A 3A 3A C2.9A 3A
854 \& <CSI> 9B 3B 3B 3B C2.9B 3B
855 \& <DC4> 14 3C 3C 3C 14 3C
856 \& <NAK> 15 3D 3D 3D 15 3D
857 \& <PM> 9E 3E 3E 3E C2.9E 3E
858 \& <SUB> 1A 3F 3F 3F 1A 3F
859 \& <SPACE> 20 40 40 40 20 40
860 \& <NON\-BREAKING SPACE> A0 41 41 41 C2.A0 80.41
861 \& <a WITH CIRCUMFLEX> E2 42 42 42 C3.A2 8B.43
862 \& <a WITH DIAERESIS> E4 43 43 43 C3.A4 8B.45
863 \& <a WITH GRAVE> E0 44 44 44 C3.A0 8B.41
864 \& <a WITH ACUTE> E1 45 45 45 C3.A1 8B.42
865 \& <a WITH TILDE> E3 46 46 46 C3.A3 8B.44
866 \& <a WITH RING ABOVE> E5 47 47 47 C3.A5 8B.46
867 \& <c WITH CEDILLA> E7 48 48 48 C3.A7 8B.48
868 \& <n WITH TILDE> F1 49 49 49 C3.B1 8B.58
869 \& <CENT SIGN> A2 4A 4A B0 C2.A2 80.43 ##
870 \& . 2E 4B 4B 4B 2E 4B
871 \& < 3C 4C 4C 4C 3C 4C
872 \& ( 28 4D 4D 4D 28 4D
873 \& + 2B 4E 4E 4E 2B 4E
874 \& | 7C 4F 4F 4F 7C 4F
875 \& & 26 50 50 50 26 50
876 \& <e WITH ACUTE> E9 51 51 51 C3.A9 8B.4A
877 \& <e WITH CIRCUMFLEX> EA 52 52 52 C3.AA 8B.51
878 \& <e WITH DIAERESIS> EB 53 53 53 C3.AB 8B.52
879 \& <e WITH GRAVE> E8 54 54 54 C3.A8 8B.49
880 \& <i WITH ACUTE> ED 55 55 55 C3.AD 8B.54
881 \& <i WITH CIRCUMFLEX> EE 56 56 56 C3.AE 8B.55
882 \& <i WITH DIAERESIS> EF 57 57 57 C3.AF 8B.56
883 \& <i WITH GRAVE> EC 58 58 58 C3.AC 8B.53
884 \& <SMALL LETTER SHARP S> DF 59 59 59 C3.9F 8A.73
885 \& ! 21 5A 5A 5A 21 5A
886 \& $ 24 5B 5B 5B 24 5B
887 \& * 2A 5C 5C 5C 2A 5C
888 \& ) 29 5D 5D 5D 29 5D
889 \& ; 3B 5E 5E 5E 3B 5E
890 \& ^ 5E B0 5F 6A 5E 5F ** ##
891 \& \- 2D 60 60 60 2D 60
892 \& / 2F 61 61 61 2F 61
893 \& <A WITH CIRCUMFLEX> C2 62 62 62 C3.82 8A.43
894 \& <A WITH DIAERESIS> C4 63 63 63 C3.84 8A.45
895 \& <A WITH GRAVE> C0 64 64 64 C3.80 8A.41
896 \& <A WITH ACUTE> C1 65 65 65 C3.81 8A.42
897 \& <A WITH TILDE> C3 66 66 66 C3.83 8A.44
898 \& <A WITH RING ABOVE> C5 67 67 67 C3.85 8A.46
899 \& <C WITH CEDILLA> C7 68 68 68 C3.87 8A.48
900 \& <N WITH TILDE> D1 69 69 69 C3.91 8A.58
901 \& <BROKEN BAR> A6 6A 6A D0 C2.A6 80.47 ##
902 \& , 2C 6B 6B 6B 2C 6B
903 \& % 25 6C 6C 6C 25 6C
904 \& _ 5F 6D 6D 6D 5F 6D
905 \& > 3E 6E 6E 6E 3E 6E
906 \& ? 3F 6F 6F 6F 3F 6F
907 \& <o WITH STROKE> F8 70 70 70 C3.B8 8B.67
908 \& <E WITH ACUTE> C9 71 71 71 C3.89 8A.4A
909 \& <E WITH CIRCUMFLEX> CA 72 72 72 C3.8A 8A.51
910 \& <E WITH DIAERESIS> CB 73 73 73 C3.8B 8A.52
911 \& <E WITH GRAVE> C8 74 74 74 C3.88 8A.49
912 \& <I WITH ACUTE> CD 75 75 75 C3.8D 8A.54
913 \& <I WITH CIRCUMFLEX> CE 76 76 76 C3.8E 8A.55
914 \& <I WITH DIAERESIS> CF 77 77 77 C3.8F 8A.56
915 \& <I WITH GRAVE> CC 78 78 78 C3.8C 8A.53
916 \& \` 60 79 79 4A 60 79 ##
917 \& : 3A 7A 7A 7A 3A 7A
918 \& # 23 7B 7B 7B 23 7B
919 \& @ 40 7C 7C 7C 40 7C
920 \& \*(Aq 27 7D 7D 7D 27 7D
921 \& = 3D 7E 7E 7E 3D 7E
922 \& " 22 7F 7F 7F 22 7F
923 \& <O WITH STROKE> D8 80 80 80 C3.98 8A.67
924 \& a 61 81 81 81 61 81
925 \& b 62 82 82 82 62 82
926 \& c 63 83 83 83 63 83
927 \& d 64 84 84 84 64 84
928 \& e 65 85 85 85 65 85
929 \& f 66 86 86 86 66 86
930 \& g 67 87 87 87 67 87
931 \& h 68 88 88 88 68 88
932 \& i 69 89 89 89 69 89
933 \& <LEFT POINTING GUILLEMET> AB 8A 8A 8A C2.AB 80.52
934 \& <RIGHT POINTING GUILLEMET> BB 8B 8B 8B C2.BB 80.6A
935 \& <SMALL LETTER eth> F0 8C 8C 8C C3.B0 8B.57
936 \& <y WITH ACUTE> FD 8D 8D 8D C3.BD 8B.71
937 \& <SMALL LETTER thorn> FE 8E 8E 8E C3.BE 8B.72
938 \& <PLUS\-OR\-MINUS SIGN> B1 8F 8F 8F C2.B1 80.58
939 \& <DEGREE SIGN> B0 90 90 90 C2.B0 80.57
940 \& j 6A 91 91 91 6A 91
941 \& k 6B 92 92 92 6B 92
942 \& l 6C 93 93 93 6C 93
943 \& m 6D 94 94 94 6D 94
944 \& n 6E 95 95 95 6E 95
945 \& o 6F 96 96 96 6F 96
946 \& p 70 97 97 97 70 97
947 \& q 71 98 98 98 71 98
948 \& r 72 99 99 99 72 99
949 \& <FEMININE ORDINAL> AA 9A 9A 9A C2.AA 80.51
950 \& <MASC. ORDINAL INDICATOR> BA 9B 9B 9B C2.BA 80.69
951 \& <SMALL LIGATURE ae> E6 9C 9C 9C C3.A6 8B.47
952 \& <CEDILLA> B8 9D 9D 9D C2.B8 80.67
953 \& <CAPITAL LIGATURE AE> C6 9E 9E 9E C3.86 8A.47
954 \& <CURRENCY SIGN> A4 9F 9F 9F C2.A4 80.45
955 \& <MICRO SIGN> B5 A0 A0 A0 C2.B5 80.64
956 \& ~ 7E A1 A1 FF 7E A1 ##
957 \& s 73 A2 A2 A2 73 A2
958 \& t 74 A3 A3 A3 74 A3
959 \& u 75 A4 A4 A4 75 A4
960 \& v 76 A5 A5 A5 76 A5
961 \& w 77 A6 A6 A6 77 A6
962 \& x 78 A7 A7 A7 78 A7
963 \& y 79 A8 A8 A8 79 A8
964 \& z 7A A9 A9 A9 7A A9
965 \& <INVERTED "!" > A1 AA AA AA C2.A1 80.42
966 \& <INVERTED QUESTION MARK> BF AB AB AB C2.BF 80.73
967 \& <CAPITAL LETTER ETH> D0 AC AC AC C3.90 8A.57
968 \& [ 5B BA AD BB 5B AD ** ##
969 \& <CAPITAL LETTER THORN> DE AE AE AE C3.9E 8A.72
970 \& <REGISTERED TRADE MARK> AE AF AF AF C2.AE 80.55
971 \& <NOT SIGN> AC 5F B0 BA C2.AC 80.53 ** ##
972 \& <POUND SIGN> A3 B1 B1 B1 C2.A3 80.44
973 \& <YEN SIGN> A5 B2 B2 B2 C2.A5 80.46
974 \& <MIDDLE DOT> B7 B3 B3 B3 C2.B7 80.66
975 \& <COPYRIGHT SIGN> A9 B4 B4 B4 C2.A9 80.4A
976 \& <SECTION SIGN> A7 B5 B5 B5 C2.A7 80.48
977 \& <PARAGRAPH SIGN> B6 B6 B6 B6 C2.B6 80.65
978 \& <FRACTION ONE QUARTER> BC B7 B7 B7 C2.BC 80.70
979 \& <FRACTION ONE HALF> BD B8 B8 B8 C2.BD 80.71
980 \& <FRACTION THREE QUARTERS> BE B9 B9 B9 C2.BE 80.72
981 \& <Y WITH ACUTE> DD AD BA AD C3.9D 8A.71 ** ##
982 \& <DIAERESIS> A8 BD BB 79 C2.A8 80.49 ** ##
983 \& <MACRON> AF BC BC A1 C2.AF 80.56 ##
984 \& ] 5D BB BD BD 5D BD **
985 \& <ACUTE ACCENT> B4 BE BE BE C2.B4 80.63
986 \& <MULTIPLICATION SIGN> D7 BF BF BF C3.97 8A.66
987 \& { 7B C0 C0 FB 7B C0 ##
988 \& A 41 C1 C1 C1 41 C1
989 \& B 42 C2 C2 C2 42 C2
990 \& C 43 C3 C3 C3 43 C3
991 \& D 44 C4 C4 C4 44 C4
992 \& E 45 C5 C5 C5 45 C5
993 \& F 46 C6 C6 C6 46 C6
994 \& G 47 C7 C7 C7 47 C7
995 \& H 48 C8 C8 C8 48 C8
996 \& I 49 C9 C9 C9 49 C9
997 \& <SOFT HYPHEN> AD CA CA CA C2.AD 80.54
998 \& <o WITH CIRCUMFLEX> F4 CB CB CB C3.B4 8B.63
999 \& <o WITH DIAERESIS> F6 CC CC CC C3.B6 8B.65
1000 \& <o WITH GRAVE> F2 CD CD CD C3.B2 8B.59
1001 \& <o WITH ACUTE> F3 CE CE CE C3.B3 8B.62
1002 \& <o WITH TILDE> F5 CF CF CF C3.B5 8B.64
1003 \& } 7D D0 D0 FD 7D D0 ##
1004 \& J 4A D1 D1 D1 4A D1
1005 \& K 4B D2 D2 D2 4B D2
1006 \& L 4C D3 D3 D3 4C D3
1007 \& M 4D D4 D4 D4 4D D4
1008 \& N 4E D5 D5 D5 4E D5
1009 \& O 4F D6 D6 D6 4F D6
1010 \& P 50 D7 D7 D7 50 D7
1011 \& Q 51 D8 D8 D8 51 D8
1012 \& R 52 D9 D9 D9 52 D9
1013 \& <SUPERSCRIPT ONE> B9 DA DA DA C2.B9 80.68
1014 \& <u WITH CIRCUMFLEX> FB DB DB DB C3.BB 8B.6A
1015 \& <u WITH DIAERESIS> FC DC DC DC C3.BC 8B.70
1016 \& <u WITH GRAVE> F9 DD DD C0 C3.B9 8B.68 ##
1017 \& <u WITH ACUTE> FA DE DE DE C3.BA 8B.69
1018 \& <y WITH DIAERESIS> FF DF DF DF C3.BF 8B.73
1019 \& \e 5C E0 E0 BC 5C E0 ##
1020 \& <DIVISION SIGN> F7 E1 E1 E1 C3.B7 8B.66
1021 \& S 53 E2 E2 E2 53 E2
1022 \& T 54 E3 E3 E3 54 E3
1023 \& U 55 E4 E4 E4 55 E4
1024 \& V 56 E5 E5 E5 56 E5
1025 \& W 57 E6 E6 E6 57 E6
1026 \& X 58 E7 E7 E7 58 E7
1027 \& Y 59 E8 E8 E8 59 E8
1028 \& Z 5A E9 E9 E9 5A E9
1029 \& <SUPERSCRIPT TWO> B2 EA EA EA C2.B2 80.59
1030 \& <O WITH CIRCUMFLEX> D4 EB EB EB C3.94 8A.63
1031 \& <O WITH DIAERESIS> D6 EC EC EC C3.96 8A.65
1032 \& <O WITH GRAVE> D2 ED ED ED C3.92 8A.59
1033 \& <O WITH ACUTE> D3 EE EE EE C3.93 8A.62
1034 \& <O WITH TILDE> D5 EF EF EF C3.95 8A.64
1035 \& 0 30 F0 F0 F0 30 F0
1036 \& 1 31 F1 F1 F1 31 F1
1037 \& 2 32 F2 F2 F2 32 F2
1038 \& 3 33 F3 F3 F3 33 F3
1039 \& 4 34 F4 F4 F4 34 F4
1040 \& 5 35 F5 F5 F5 35 F5
1041 \& 6 36 F6 F6 F6 36 F6
1042 \& 7 37 F7 F7 F7 37 F7
1043 \& 8 38 F8 F8 F8 38 F8
1044 \& 9 39 F9 F9 F9 39 F9
1045 \& <SUPERSCRIPT THREE> B3 FA FA FA C2.B3 80.62
1046 \& <U WITH CIRCUMFLEX> DB FB FB DD C3.9B 8A.6A ##
1047 \& <U WITH DIAERESIS> DC FC FC FC C3.9C 8A.70
1048 \& <U WITH GRAVE> D9 FD FD E0 C3.99 8A.68 ##
1049 \& <U WITH ACUTE> DA FE FE FE C3.9A 8A.69
1050 \& <APC> 9F FF FF 5F C2.9F FF ##
1051 .Ve
1052 .SH "IDENTIFYING CHARACTER CODE SETS"
1053 .IX Header "IDENTIFYING CHARACTER CODE SETS"
1054 It is possible to determine which character set you are operating under.
1055 But first you need to be really really sure you need to do this. Your
1056 code will be simpler and probably just as portable if you don't have
1057 to test the character set and do different things, depending. There are
1058 actually only very few circumstances where it's not easy to write
1059 straight-line code portable to all character sets. See
1060 "Unicode and EBCDIC" in perluniintro for how to portably specify
1061 characters.
1062 .PP
1063 But there are some cases where you may want to know which character set
1064 you are running under. One possible example is doing
1065 sorting in inner loops where performance is critical.
1066 .PP
1067 To determine if you are running under ASCII or EBCDIC, you can use the
1068 return value of \f(CWord()\fR or \f(CWchr()\fR to test one or more character
1069 values. For example:
1070 .PP
1071 .Vb 4
1072 \& $is_ascii = "A" eq chr(65);
1073 \& $is_ebcdic = "A" eq chr(193);
1074 \& $is_ascii = ord("A") == 65;
1075 \& $is_ebcdic = ord("A") == 193;
1076 .Ve
1077 .PP
1078 There's even less need to distinguish between EBCDIC code pages, but to
1079 do so try looking at one or more of the characters that differ between
1080 them.
1081 .PP
1082 .Vb 4
1083 \& $is_ascii = ord(\*(Aq[\*(Aq) == 91;
1084 \& $is_ebcdic_37 = ord(\*(Aq[\*(Aq) == 186;
1085 \& $is_ebcdic_1047 = ord(\*(Aq[\*(Aq) == 173;
1086 \& $is_ebcdic_POSIX_BC = ord(\*(Aq[\*(Aq) == 187;
1087 .Ve
1088 .PP
1089 However, it would be unwise to write tests such as:
1090 .PP
1091 .Vb 2
1092 \& $is_ascii = "\er" ne chr(13); # WRONG
1093 \& $is_ascii = "\en" ne chr(10); # ILL ADVISED
1094 .Ve
1095 .PP
1096 Obviously the first of these will fail to distinguish most ASCII
1097 platforms from either a CCSID 0037, a 1047, or a POSIX-BC EBCDIC
1098 platform since \f(CW\*(C`"\er"\ eq\ chr(13)\*(C'\fR under all of those coded character
1099 sets. But note too that because \f(CW"\en"\fR is \f(CWchr(13)\fR and \f(CW"\er"\fR is
1100 \&\f(CWchr(10)\fR on old Macintosh (which is an ASCII platform) the second
1101 \&\f(CW$is_ascii\fR test will lead to trouble there.
1102 .PP
1103 To determine whether or not perl was built under an EBCDIC
1104 code page you can use the Config module like so:
1105 .PP
1106 .Vb 2
1107 \& use Config;
1108 \& $is_ebcdic = $Config{\*(Aqebcdic\*(Aq} eq \*(Aqdefine\*(Aq;
1109 .Ve
1110 .SH CONVERSIONS
1111 .IX Header "CONVERSIONS"
1112 .ie n .SS "utf8::unicode_to_native() and utf8::native_to_unicode()"
1113 .el .SS "\f(CWutf8::unicode_to_native()\fP and \f(CWutf8::native_to_unicode()\fP"
1114 .IX Subsection "utf8::unicode_to_native() and utf8::native_to_unicode()"
1115 These functions take an input numeric code point in one encoding and
1116 return what its equivalent value is in the other.
1117 .PP
1118 See utf8.
1119 .SS tr///
1120 .IX Subsection "tr///"
1121 In order to convert a string of characters from one character set to
1122 another a simple list of numbers, such as in the right columns in the
1123 above table, along with Perl's \f(CW\*(C`tr///\*(C'\fR operator is all that is needed.
1124 The data in the table are in ASCII/Latin1 order, hence the EBCDIC columns
1125 provide easy-to-use ASCII/Latin1 to EBCDIC operations that are also easily
1126 reversed.
1127 .PP
1128 For example, to convert ASCII/Latin1 to code page 037 take the output of the
1129 second numbers column from the output of recipe 2 (modified to add
1130 \&\f(CW"\e"\fR characters), and use it in \f(CW\*(C`tr///\*(C'\fR like so:
1131 .PP
1132 .Vb 10
1133 \& $cp_037 =
1134 \& \*(Aq\ex00\ex01\ex02\ex03\ex37\ex2D\ex2E\ex2F\ex16\ex05\ex25\ex0B\ex0C\ex0D\ex0E\ex0F\*(Aq .
1135 \& \*(Aq\ex10\ex11\ex12\ex13\ex3C\ex3D\ex32\ex26\ex18\ex19\ex3F\ex27\ex1C\ex1D\ex1E\ex1F\*(Aq .
1136 \& \*(Aq\ex40\ex5A\ex7F\ex7B\ex5B\ex6C\ex50\ex7D\ex4D\ex5D\ex5C\ex4E\ex6B\ex60\ex4B\ex61\*(Aq .
1137 \& \*(Aq\exF0\exF1\exF2\exF3\exF4\exF5\exF6\exF7\exF8\exF9\ex7A\ex5E\ex4C\ex7E\ex6E\ex6F\*(Aq .
1138 \& \*(Aq\ex7C\exC1\exC2\exC3\exC4\exC5\exC6\exC7\exC8\exC9\exD1\exD2\exD3\exD4\exD5\exD6\*(Aq .
1139 \& \*(Aq\exD7\exD8\exD9\exE2\exE3\exE4\exE5\exE6\exE7\exE8\exE9\exBA\exE0\exBB\exB0\ex6D\*(Aq .
1140 \& \*(Aq\ex79\ex81\ex82\ex83\ex84\ex85\ex86\ex87\ex88\ex89\ex91\ex92\ex93\ex94\ex95\ex96\*(Aq .
1141 \& \*(Aq\ex97\ex98\ex99\exA2\exA3\exA4\exA5\exA6\exA7\exA8\exA9\exC0\ex4F\exD0\exA1\ex07\*(Aq .
1142 \& \*(Aq\ex20\ex21\ex22\ex23\ex24\ex15\ex06\ex17\ex28\ex29\ex2A\ex2B\ex2C\ex09\ex0A\ex1B\*(Aq .
1143 \& \*(Aq\ex30\ex31\ex1A\ex33\ex34\ex35\ex36\ex08\ex38\ex39\ex3A\ex3B\ex04\ex14\ex3E\exFF\*(Aq .
1144 \& \*(Aq\ex41\exAA\ex4A\exB1\ex9F\exB2\ex6A\exB5\exBD\exB4\ex9A\ex8A\ex5F\exCA\exAF\exBC\*(Aq .
1145 \& \*(Aq\ex90\ex8F\exEA\exFA\exBE\exA0\exB6\exB3\ex9D\exDA\ex9B\ex8B\exB7\exB8\exB9\exAB\*(Aq .
1146 \& \*(Aq\ex64\ex65\ex62\ex66\ex63\ex67\ex9E\ex68\ex74\ex71\ex72\ex73\ex78\ex75\ex76\ex77\*(Aq .
1147 \& \*(Aq\exAC\ex69\exED\exEE\exEB\exEF\exEC\exBF\ex80\exFD\exFE\exFB\exFC\exAD\exAE\ex59\*(Aq .
1148 \& \*(Aq\ex44\ex45\ex42\ex46\ex43\ex47\ex9C\ex48\ex54\ex51\ex52\ex53\ex58\ex55\ex56\ex57\*(Aq .
1149 \& \*(Aq\ex8C\ex49\exCD\exCE\exCB\exCF\exCC\exE1\ex70\exDD\exDE\exDB\exDC\ex8D\ex8E\exDF\*(Aq;
1150 \&
1151 \& my $ebcdic_string = $ascii_string;
1152 \& eval \*(Aq$ebcdic_string =~ tr/\e000\-\e377/\*(Aq . $cp_037 . \*(Aq/\*(Aq;
1153 .Ve
1154 .PP
1155 To convert from EBCDIC 037 to ASCII just reverse the order of the tr///
1156 arguments like so:
1157 .PP
1158 .Vb 2
1159 \& my $ascii_string = $ebcdic_string;
1160 \& eval \*(Aq$ascii_string =~ tr/\*(Aq . $cp_037 . \*(Aq/\e000\-\e377/\*(Aq;
1161 .Ve
1162 .PP
1163 Similarly one could take the output of the third numbers column from recipe 2
1164 to obtain a \f(CW$cp_1047\fR table. The fourth numbers column of the output from
1165 recipe 2 could provide a \f(CW$cp_posix_bc\fR table suitable for transcoding as
1166 well.
1167 .PP
1168 If you wanted to see the inverse tables, you would first have to sort on the
1169 desired numbers column as in recipes 4, 5 or 6, then take the output of the
1170 first numbers column.
1171 .SS iconv
1172 .IX Subsection "iconv"
1173 XPG operability often implies the presence of an \fIiconv\fR utility
1174 available from the shell or from the C library. Consult your system's
1175 documentation for information on iconv.
1176 .PP
1177 On OS/390 or z/OS see the \fBiconv\fR\|(1) manpage. One way to invoke the \f(CW\*(C`iconv\*(C'\fR
1178 shell utility from within perl would be to:
1179 .PP
1180 .Vb 2
1181 \& # OS/390 or z/OS example
1182 \& $ascii_data = \`echo \*(Aq$ebcdic_data\*(Aq| iconv \-f IBM\-1047 \-t ISO8859\-1\`
1183 .Ve
1184 .PP
1185 or the inverse map:
1186 .PP
1187 .Vb 2
1188 \& # OS/390 or z/OS example
1189 \& $ebcdic_data = \`echo \*(Aq$ascii_data\*(Aq| iconv \-f ISO8859\-1 \-t IBM\-1047\`
1190 .Ve
1191 .PP
1192 For other Perl-based conversion options see the \f(CW\*(C`Convert::*\*(C'\fR modules on CPAN.
1193 .SS "C RTL"
1194 .IX Subsection "C RTL"
1195 The OS/390 and z/OS C run-time libraries provide \f(CW_atoe()\fR and \f(CW_etoa()\fR functions.
1196 .SH "OPERATOR DIFFERENCES"
1197 .IX Header "OPERATOR DIFFERENCES"
1198 The \f(CW\*(C`..\*(C'\fR range operator treats certain character ranges with
1199 care on EBCDIC platforms. For example the following array
1200 will have twenty six elements on either an EBCDIC platform
1201 or an ASCII platform:
1202 .PP
1203 .Vb 1
1204 \& @alphabet = (\*(AqA\*(Aq..\*(AqZ\*(Aq); # $#alphabet == 25
1205 .Ve
1206 .PP
1207 The bitwise operators such as & ^ | may return different results
1208 when operating on string or character data in a Perl program running
1209 on an EBCDIC platform than when run on an ASCII platform. Here is
1210 an example adapted from the one in perlop:
1211 .PP
1212 .Vb 5
1213 \& # EBCDIC\-based examples
1214 \& print "j p \en" ^ " a h"; # prints "JAPH\en"
1215 \& print "JA" | " ph\en"; # prints "japh\en"
1216 \& print "JAPH\enJunk" & "\e277\e277\e277\e277\e277"; # prints "japh\en";
1217 \& print \*(Aqp N$\*(Aq ^ " E<H\en"; # prints "Perl\en";
1218 .Ve
1219 .PP
1220 An interesting property of the 32 C0 control characters
1221 in the ASCII table is that they can "literally" be constructed
1222 as control characters in Perl, e.g. \f(CW\*(C`(chr(0)\*(C'\fR eq \f(CW\*(C`\ec@\*(C'\fR)>
1223 \&\f(CW\*(C`(chr(1)\*(C'\fR eq \f(CW\*(C`\ecA\*(C'\fR)>, and so on. Perl on EBCDIC platforms has been
1224 ported to take \f(CW\*(C`\ec@\*(C'\fR to \f(CWchr(0)\fR and \f(CW\*(C`\ecA\*(C'\fR to \f(CWchr(1)\fR, etc. as well, but the
1225 characters that result depend on which code page you are
1226 using. The table below uses the standard acronyms for the controls.
1227 The POSIX-BC and 1047 sets are
1228 identical throughout this range and differ from the 0037 set at only
1229 one spot (21 decimal). Note that the line terminator character
1230 may be generated by \f(CW\*(C`\ecJ\*(C'\fR on ASCII platforms but by \f(CW\*(C`\ecU\*(C'\fR on 1047 or POSIX-BC
1231 platforms and cannot be generated as a \f(CW"\ec.letter."\fR control character on
1232 0037 platforms. Note also that \f(CW\*(C`\ec\e\*(C'\fR cannot be the final element in a string
1233 or regex, as it will absorb the terminator. But \f(CW\*(C`\ec\e\fR\f(CIX\fR\f(CW\*(C'\fR is a \f(CW\*(C`FILE
1234 SEPARATOR\*(C'\fR concatenated with \fIX\fR for all \fIX\fR.
1235 The outlier \f(CW\*(C`\ec?\*(C'\fR on ASCII, which yields a non\-C0 control \f(CW\*(C`DEL\*(C'\fR,
1236 yields the outlier control \f(CW\*(C`APC\*(C'\fR on EBCDIC, the one that isn't in the
1237 block of contiguous controls. Note that a subtlety of this is that
1238 \&\f(CW\*(C`\ec?\*(C'\fR on ASCII platforms is an ASCII character, while it isn't
1239 equivalent to any ASCII character in EBCDIC platforms.
1240 .PP
1241 .Vb 10
1242 \& chr ord 8859\-1 0037 1047 && POSIX\-BC
1243 \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
1244 \& \ec@ 0 <NUL> <NUL> <NUL>
1245 \& \ecA 1 <SOH> <SOH> <SOH>
1246 \& \ecB 2 <STX> <STX> <STX>
1247 \& \ecC 3 <ETX> <ETX> <ETX>
1248 \& \ecD 4 <EOT> <ST> <ST>
1249 \& \ecE 5 <ENQ> <HT> <HT>
1250 \& \ecF 6 <ACK> <SSA> <SSA>
1251 \& \ecG 7 <BEL> <DEL> <DEL>
1252 \& \ecH 8 <BS> <EPA> <EPA>
1253 \& \ecI 9 <HT> <RI> <RI>
1254 \& \ecJ 10 <LF> <SS2> <SS2>
1255 \& \ecK 11 <VT> <VT> <VT>
1256 \& \ecL 12 <FF> <FF> <FF>
1257 \& \ecM 13 <CR> <CR> <CR>
1258 \& \ecN 14 <SO> <SO> <SO>
1259 \& \ecO 15 <SI> <SI> <SI>
1260 \& \ecP 16 <DLE> <DLE> <DLE>
1261 \& \ecQ 17 <DC1> <DC1> <DC1>
1262 \& \ecR 18 <DC2> <DC2> <DC2>
1263 \& \ecS 19 <DC3> <DC3> <DC3>
1264 \& \ecT 20 <DC4> <OSC> <OSC>
1265 \& \ecU 21 <NAK> <NEL> <LF> **
1266 \& \ecV 22 <SYN> <BS> <BS>
1267 \& \ecW 23 <ETB> <ESA> <ESA>
1268 \& \ecX 24 <CAN> <CAN> <CAN>
1269 \& \ecY 25 <EOM> <EOM> <EOM>
1270 \& \ecZ 26 <SUB> <PU2> <PU2>
1271 \& \ec[ 27 <ESC> <SS3> <SS3>
1272 \& \ec\eX 28 <FS>X <FS>X <FS>X
1273 \& \ec] 29 <GS> <GS> <GS>
1274 \& \ec^ 30 <RS> <RS> <RS>
1275 \& \ec_ 31 <US> <US> <US>
1276 \& \ec? * <DEL> <APC> <APC>
1277 .Ve
1278 .PP
1279 \&\f(CW\*(C`*\*(C'\fR Note: \f(CW\*(C`\ec?\*(C'\fR maps to ordinal 127 (\f(CW\*(C`DEL\*(C'\fR) on ASCII platforms, but
1280 since ordinal 127 is a not a control character on EBCDIC machines,
1281 \&\f(CW\*(C`\ec?\*(C'\fR instead maps on them to \f(CW\*(C`APC\*(C'\fR, which is 255 in 0037 and 1047,
1282 and 95 in POSIX-BC.
1283 .SH "FUNCTION DIFFERENCES"
1284 .IX Header "FUNCTION DIFFERENCES"
1285 .ie n .IP chr() 8
1286 .el .IP \f(CWchr()\fR 8
1287 .IX Item "chr()"
1288 \&\f(CWchr()\fR must be given an EBCDIC code number argument to yield a desired
1289 character return value on an EBCDIC platform. For example:
1290 .Sp
1291 .Vb 1
1292 \& $CAPITAL_LETTER_A = chr(193);
1293 .Ve
1294 .ie n .IP ord() 8
1295 .el .IP \f(CWord()\fR 8
1296 .IX Item "ord()"
1297 \&\f(CWord()\fR will return EBCDIC code number values on an EBCDIC platform.
1298 For example:
1299 .Sp
1300 .Vb 1
1301 \& $the_number_193 = ord("A");
1302 .Ve
1303 .ie n .IP pack() 8
1304 .el .IP \f(CWpack()\fR 8
1305 .IX Item "pack()"
1306 The \f(CW"c"\fR and \f(CW"C"\fR templates for \f(CWpack()\fR are dependent upon character set
1307 encoding. Examples of usage on EBCDIC include:
1308 .Sp
1309 .Vb 4
1310 \& $foo = pack("CCCC",193,194,195,196);
1311 \& # $foo eq "ABCD"
1312 \& $foo = pack("C4",193,194,195,196);
1313 \& # same thing
1314 \&
1315 \& $foo = pack("ccxxcc",193,194,195,196);
1316 \& # $foo eq "AB\e0\e0CD"
1317 .Ve
1318 .Sp
1319 The \f(CW"U"\fR template has been ported to mean "Unicode" on all platforms so
1320 that
1321 .Sp
1322 .Vb 1
1323 \& pack("U", 65) eq \*(AqA\*(Aq
1324 .Ve
1325 .Sp
1326 is true on all platforms. If you want native code points for the low
1327 256, use the \f(CW"W"\fR template. This means that the equivalences
1328 .Sp
1329 .Vb 2
1330 \& pack("W", ord($character)) eq $character
1331 \& unpack("W", $character) == ord $character
1332 .Ve
1333 .Sp
1334 will hold.
1335 .ie n .IP print() 8
1336 .el .IP \f(CWprint()\fR 8
1337 .IX Item "print()"
1338 One must be careful with scalars and strings that are passed to
1339 print that contain ASCII encodings. One common place
1340 for this to occur is in the output of the MIME type header for
1341 CGI script writing. For example, many Perl programming guides
1342 recommend something similar to:
1343 .Sp
1344 .Vb 2
1345 \& print "Content\-type:\ettext/html\e015\e012\e015\e012";
1346 \& # this may be wrong on EBCDIC
1347 .Ve
1348 .Sp
1349 You can instead write
1350 .Sp
1351 .Vb 1
1352 \& print "Content\-type:\ettext/html\er\en\er\en"; # OK for DGW et al
1353 .Ve
1354 .Sp
1355 and have it work portably.
1356 .Sp
1357 That is because the translation from EBCDIC to ASCII is done
1358 by the web server in this case. Consult your web server's documentation for
1359 further details.
1360 .ie n .IP printf() 8
1361 .el .IP \f(CWprintf()\fR 8
1362 .IX Item "printf()"
1363 The formats that can convert characters to numbers and vice versa
1364 will be different from their ASCII counterparts when executed
1365 on an EBCDIC platform. Examples include:
1366 .Sp
1367 .Vb 1
1368 \& printf("%c%c%c",193,194,195); # prints ABC
1369 .Ve
1370 .ie n .IP sort() 8
1371 .el .IP \f(CWsort()\fR 8
1372 .IX Item "sort()"
1373 EBCDIC sort results may differ from ASCII sort results especially for
1374 mixed case strings. This is discussed in more detail below.
1375 .ie n .IP sprintf() 8
1376 .el .IP \f(CWsprintf()\fR 8
1377 .IX Item "sprintf()"
1378 See the discussion of \f(CW"printf()"\fR above. An example of the use
1379 of sprintf would be:
1380 .Sp
1381 .Vb 1
1382 \& $CAPITAL_LETTER_A = sprintf("%c",193);
1383 .Ve
1384 .ie n .IP unpack() 8
1385 .el .IP \f(CWunpack()\fR 8
1386 .IX Item "unpack()"
1387 See the discussion of \f(CW"pack()"\fR above.
1388 .PP
1389 Note that it is possible to write portable code for these by specifying
1390 things in Unicode numbers, and using a conversion function:
1391 .PP
1392 .Vb 3
1393 \& printf("%c",utf8::unicode_to_native(65)); # prints A on all
1394 \& # platforms
1395 \& print utf8::native_to_unicode(ord("A")); # Likewise, prints 65
1396 .Ve
1397 .PP
1398 See "Unicode and EBCDIC" in perluniintro and "CONVERSIONS"
1399 for other options.
1400 .SH "REGULAR EXPRESSION DIFFERENCES"
1401 .IX Header "REGULAR EXPRESSION DIFFERENCES"
1402 You can write your regular expressions just like someone on an ASCII
1403 platform would do. But keep in mind that using octal or hex notation to
1404 specify a particular code point will give you the character that the
1405 EBCDIC code page natively maps to it. (This is also true of all
1406 double-quoted strings.) If you want to write portably, just use the
1407 \&\f(CW\*(C`\eN{U+...}\*(C'\fR notation everywhere where you would have used \f(CW\*(C`\ex{...}\*(C'\fR,
1408 and don't use octal notation at all.
1409 .PP
1410 Starting in Perl v5.22, this applies to ranges in bracketed character
1411 classes. If you say, for example, \f(CW\*(C`qr/[\eN{U+20}\-\eN{U+7F}]/\*(C'\fR, it means
1412 the characters \f(CW\*(C`\eN{U+20}\*(C'\fR, \f(CW\*(C`\eN{U+21}\*(C'\fR, ..., \f(CW\*(C`\eN{U+7F}\*(C'\fR. This range
1413 is all the printable characters that the ASCII character set contains.
1414 .PP
1415 Prior to v5.22, you couldn't specify any ranges portably, except
1416 (starting in Perl v5.5.3) all subsets of the \f(CW\*(C`[A\-Z]\*(C'\fR and \f(CW\*(C`[a\-z]\*(C'\fR
1417 ranges are specially coded to not pick up gap characters. For example,
1418 characters such as "ô" (\f(CW\*(C`o WITH CIRCUMFLEX\*(C'\fR) that lie between
1419 "I" and "J" would not be matched by the regular expression range
1420 \&\f(CW\*(C`/[H\-K]/\*(C'\fR. But if either of the range end points is explicitly numeric
1421 (and neither is specified by \f(CW\*(C`\eN{U+...}\*(C'\fR), the gap characters are
1422 matched:
1423 .PP
1424 .Vb 1
1425 \& /[\ex89\-\ex91]/
1426 .Ve
1427 .PP
1428 will match \f(CW\*(C`\ex8e\*(C'\fR, even though \f(CW\*(C`\ex89\*(C'\fR is "i" and \f(CW\*(C`\ex91 \*(C'\fR is "j",
1429 and \f(CW\*(C`\ex8e\*(C'\fR is a gap character, from the alphabetic viewpoint.
1430 .PP
1431 Another construct to be wary of is the inappropriate use of hex (unless
1432 you use \f(CW\*(C`\eN{U+...}\*(C'\fR) or
1433 octal constants in regular expressions. Consider the following
1434 set of subs:
1435 .PP
1436 .Vb 4
1437 \& sub is_c0 {
1438 \& my $char = substr(shift,0,1);
1439 \& $char =~ /[\e000\-\e037]/;
1440 \& }
1441 \&
1442 \& sub is_print_ascii {
1443 \& my $char = substr(shift,0,1);
1444 \& $char =~ /[\e040\-\e176]/;
1445 \& }
1446 \&
1447 \& sub is_delete {
1448 \& my $char = substr(shift,0,1);
1449 \& $char eq "\e177";
1450 \& }
1451 \&
1452 \& sub is_c1 {
1453 \& my $char = substr(shift,0,1);
1454 \& $char =~ /[\e200\-\e237]/;
1455 \& }
1456 \&
1457 \& sub is_latin_1 { # But not ASCII; not C1
1458 \& my $char = substr(shift,0,1);
1459 \& $char =~ /[\e240\-\e377]/;
1460 \& }
1461 .Ve
1462 .PP
1463 These are valid only on ASCII platforms. Starting in Perl v5.22, simply
1464 changing the octal constants to equivalent \f(CW\*(C`\eN{U+...}\*(C'\fR values makes
1465 them portable:
1466 .PP
1467 .Vb 4
1468 \& sub is_c0 {
1469 \& my $char = substr(shift,0,1);
1470 \& $char =~ /[\eN{U+00}\-\eN{U+1F}]/;
1471 \& }
1472 \&
1473 \& sub is_print_ascii {
1474 \& my $char = substr(shift,0,1);
1475 \& $char =~ /[\eN{U+20}\-\eN{U+7E}]/;
1476 \& }
1477 \&
1478 \& sub is_delete {
1479 \& my $char = substr(shift,0,1);
1480 \& $char eq "\eN{U+7F}";
1481 \& }
1482 \&
1483 \& sub is_c1 {
1484 \& my $char = substr(shift,0,1);
1485 \& $char =~ /[\eN{U+80}\-\eN{U+9F}]/;
1486 \& }
1487 \&
1488 \& sub is_latin_1 { # But not ASCII; not C1
1489 \& my $char = substr(shift,0,1);
1490 \& $char =~ /[\eN{U+A0}\-\eN{U+FF}]/;
1491 \& }
1492 .Ve
1493 .PP
1494 And here are some alternative portable ways to write them:
1495 .PP
1496 .Vb 3
1497 \& sub Is_c0 {
1498 \& my $char = substr(shift,0,1);
1499 \& return $char =~ /[[:cntrl:]]/a && ! Is_delete($char);
1500 \&
1501 \& # Alternatively:
1502 \& # return $char =~ /[[:cntrl:]]/
1503 \& # && $char =~ /[[:ascii:]]/
1504 \& # && ! Is_delete($char);
1505 \& }
1506 \&
1507 \& sub Is_print_ascii {
1508 \& my $char = substr(shift,0,1);
1509 \&
1510 \& return $char =~ /[[:print:]]/a;
1511 \&
1512 \& # Alternatively:
1513 \& # return $char =~ /[[:print:]]/ && $char =~ /[[:ascii:]]/;
1514 \&
1515 \& # Or
1516 \& # return $char
1517 \& # =~ /[ !"\e#\e$%&\*(Aq()*+,\e\-.\e/0\-9:;<=>?\e@A\-Z[\e\e\e]^_\`a\-z{|}~]/;
1518 \& }
1519 \&
1520 \& sub Is_delete {
1521 \& my $char = substr(shift,0,1);
1522 \& return utf8::native_to_unicode(ord $char) == 0x7F;
1523 \& }
1524 \&
1525 \& sub Is_c1 {
1526 \& use feature \*(Aqunicode_strings\*(Aq;
1527 \& my $char = substr(shift,0,1);
1528 \& return $char =~ /[[:cntrl:]]/ && $char !~ /[[:ascii:]]/;
1529 \& }
1530 \&
1531 \& sub Is_latin_1 { # But not ASCII; not C1
1532 \& use feature \*(Aqunicode_strings\*(Aq;
1533 \& my $char = substr(shift,0,1);
1534 \& return ord($char) < 256
1535 \& && $char !~ /[[:ascii:]]/
1536 \& && $char !~ /[[:cntrl:]]/;
1537 \& }
1538 .Ve
1539 .PP
1540 Another way to write \f(CWIs_latin_1()\fR would be
1541 to use the characters in the range explicitly:
1542 .PP
1543 .Vb 5
1544 \& sub Is_latin_1 {
1545 \& my $char = substr(shift,0,1);
1546 \& $char =~ /[\ ¡¢£¤¥¦§¨©ª«¬\%®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ]
1547 \& [ÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ]/x;
1548 \& }
1549 .Ve
1550 .PP
1551 Although that form may run into trouble in network transit (due to the
1552 presence of 8 bit characters) or on non ISO-Latin character sets. But
1553 it does allow \f(CW\*(C`Is_c1\*(C'\fR to be rewritten so it works on Perls that don't
1554 have \f(CW\*(Aqunicode_strings\*(Aq\fR (earlier than v5.14):
1555 .PP
1556 .Vb 6
1557 \& sub Is_latin_1 { # But not ASCII; not C1
1558 \& my $char = substr(shift,0,1);
1559 \& return ord($char) < 256
1560 \& && $char !~ /[[:ascii:]]/
1561 \& && ! Is_latin1($char);
1562 \& }
1563 .Ve
1564 .SH SOCKETS
1565 .IX Header "SOCKETS"
1566 Most socket programming assumes ASCII character encodings in network
1567 byte order. Exceptions can include CGI script writing under a
1568 host web server where the server may take care of translation for you.
1569 Most host web servers convert EBCDIC data to ISO\-8859\-1 or Unicode on
1570 output.
1571 .SH SORTING
1572 .IX Header "SORTING"
1573 One big difference between ASCII-based character sets and EBCDIC ones
1574 are the relative positions of the characters when sorted in native
1575 order. Of most concern are the upper\- and lowercase letters, the
1576 digits, and the underscore (\f(CW"_"\fR). On ASCII platforms the native sort
1577 order has the digits come before the uppercase letters which come before
1578 the underscore which comes before the lowercase letters. On EBCDIC, the
1579 underscore comes first, then the lowercase letters, then the uppercase
1580 ones, and the digits last. If sorted on an ASCII-based platform, the
1581 two-letter abbreviation for a physician comes before the two letter
1582 abbreviation for drive; that is:
1583 .PP
1584 .Vb 2
1585 \& @sorted = sort(qw(Dr. dr.)); # @sorted holds (\*(AqDr.\*(Aq,\*(Aqdr.\*(Aq) on ASCII,
1586 \& # but (\*(Aqdr.\*(Aq,\*(AqDr.\*(Aq) on EBCDIC
1587 .Ve
1588 .PP
1589 The property of lowercase before uppercase letters in EBCDIC is
1590 even carried to the Latin 1 EBCDIC pages such as 0037 and 1047.
1591 An example would be that "Ë" (\f(CW\*(C`E WITH DIAERESIS\*(C'\fR, 203) comes
1592 before "ë" (\f(CW\*(C`e WITH DIAERESIS\*(C'\fR, 235) on an ASCII platform, but
1593 the latter (83) comes before the former (115) on an EBCDIC platform.
1594 (Astute readers will note that the uppercase version of "ß"
1595 \&\f(CW\*(C`SMALL LETTER SHARP S\*(C'\fR is simply "SS" and that the upper case versions
1596 of "ÿ" (small \f(CW\*(C`y WITH DIAERESIS\*(C'\fR) and "µ" (\f(CW\*(C`MICRO SIGN\*(C'\fR)
1597 are not in the 0..255 range but are in Unicode, in a Unicode enabled
1598 Perl).
1599 .PP
1600 The sort order will cause differences between results obtained on
1601 ASCII platforms versus EBCDIC platforms. What follows are some suggestions
1602 on how to deal with these differences.
1603 .SS "Ignore ASCII vs. EBCDIC sort differences"
1604 .IX Subsection "Ignore ASCII vs. EBCDIC sort differences"
1605 This is the least computationally expensive strategy. It may require
1606 some user education.
1607 .SS "Use a sort helper function"
1608 .IX Subsection "Use a sort helper function"
1609 This is completely general, but the most computationally expensive
1610 strategy. Choose one or the other character set and transform to that
1611 for every sort comparison. Here's a complete example that transforms
1612 to ASCII sort order:
1613 .PP
1614 .Vb 2
1615 \& sub native_to_uni($) {
1616 \& my $string = shift;
1617 \&
1618 \& # Saves time on an ASCII platform
1619 \& return $string if ord \*(AqA\*(Aq == 65;
1620 \&
1621 \& my $output = "";
1622 \& for my $i (0 .. length($string) \- 1) {
1623 \& $output
1624 \& .= chr(utf8::native_to_unicode(ord(substr($string, $i, 1))));
1625 \& }
1626 \&
1627 \& # Preserve utf8ness of input onto the output, even if it didn\*(Aqt need
1628 \& # to be utf8
1629 \& utf8::upgrade($output) if utf8::is_utf8($string);
1630 \&
1631 \& return $output;
1632 \& }
1633 \&
1634 \& sub ascii_order { # Sort helper
1635 \& return native_to_uni($a) cmp native_to_uni($b);
1636 \& }
1637 \&
1638 \& sort ascii_order @list;
1639 .Ve
1640 .SS "MONO CASE then sort data (for non-digits, non-underscore)"
1641 .IX Subsection "MONO CASE then sort data (for non-digits, non-underscore)"
1642 If you don't care about where digits and underscore sort to, you can do
1643 something like this
1644 .PP
1645 .Vb 3
1646 \& sub case_insensitive_order { # Sort helper
1647 \& return lc($a) cmp lc($b)
1648 \& }
1649 \&
1650 \& sort case_insensitive_order @list;
1651 .Ve
1652 .PP
1653 If performance is an issue, and you don't care if the output is in the
1654 same case as the input, Use \f(CW\*(C`tr///\*(C'\fR to transform to the case most
1655 employed within the data. If the data are primarily UPPERCASE
1656 non\-Latin1, then apply \f(CW\*(C`tr/[a\-z]/[A\-Z]/\*(C'\fR, and then \f(CWsort()\fR. If the
1657 data are primarily lowercase non Latin1 then apply \f(CW\*(C`tr/[A\-Z]/[a\-z]/\*(C'\fR
1658 before sorting. If the data are primarily UPPERCASE and include Latin\-1
1659 characters then apply:
1660 .PP
1661 .Vb 3
1662 \& tr/[a\-z]/[A\-Z]/;
1663 \& tr/[àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ]/[ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ/;
1664 \& s/ß/SS/g;
1665 .Ve
1666 .PP
1667 then \f(CWsort()\fR. If you have a choice, it's better to lowercase things
1668 to avoid the problems of the two Latin\-1 characters whose uppercase is
1669 outside Latin\-1: "ÿ" (small \f(CW\*(C`y WITH DIAERESIS\*(C'\fR) and "µ"
1670 (\f(CW\*(C`MICRO SIGN\*(C'\fR). If you do need to upppercase, you can; with a
1671 Unicode-enabled Perl, do:
1672 .PP
1673 .Vb 2
1674 \& tr/ÿ/\ex{178}/;
1675 \& tr/µ/\ex{39C}/;
1676 .Ve
1677 .SS "Perform sorting on one type of platform only"
1678 .IX Subsection "Perform sorting on one type of platform only"
1679 This strategy can employ a network connection. As such
1680 it would be computationally expensive.
1681 .SH "TRANSFORMATION FORMATS"
1682 .IX Header "TRANSFORMATION FORMATS"
1683 There are a variety of ways of transforming data with an intra character set
1684 mapping that serve a variety of purposes. Sorting was discussed in the
1685 previous section and a few of the other more popular mapping techniques are
1686 discussed next.
1687 .SS "URL decoding and encoding"
1688 .IX Subsection "URL decoding and encoding"
1689 Note that some URLs have hexadecimal ASCII code points in them in an
1690 attempt to overcome character or protocol limitation issues. For example
1691 the tilde character is not on every keyboard hence a URL of the form:
1692 .PP
1693 .Vb 1
1694 \& http://www.pvhp.com/~pvhp/
1695 .Ve
1696 .PP
1697 may also be expressed as either of:
1698 .PP
1699 .Vb 1
1700 \& http://www.pvhp.com/%7Epvhp/
1701 \&
1702 \& http://www.pvhp.com/%7epvhp/
1703 .Ve
1704 .PP
1705 where 7E is the hexadecimal ASCII code point for "~". Here is an example
1706 of decoding such a URL in any EBCDIC code page:
1707 .PP
1708 .Vb 3
1709 \& $url = \*(Aqhttp://www.pvhp.com/%7Epvhp/\*(Aq;
1710 \& $url =~ s/%([0\-9a\-fA\-F]{2})/
1711 \& pack("c",utf8::unicode_to_native(hex($1)))/xge;
1712 .Ve
1713 .PP
1714 Conversely, here is a partial solution for the task of encoding such
1715 a URL in any EBCDIC code page:
1716 .PP
1717 .Vb 5
1718 \& $url = \*(Aqhttp://www.pvhp.com/~pvhp/\*(Aq;
1719 \& # The following regular expression does not address the
1720 \& # mappings for: (\*(Aq.\*(Aq => \*(Aq%2E\*(Aq, \*(Aq/\*(Aq => \*(Aq%2F\*(Aq, \*(Aq:\*(Aq => \*(Aq%3A\*(Aq)
1721 \& $url =~ s/([\et "#%&\e(\e),;<=>\e?\e@\e[\e\e\e]^\`{|}~])/
1722 \& sprintf("%%%02X",utf8::native_to_unicode(ord($1)))/xge;
1723 .Ve
1724 .PP
1725 where a more complete solution would split the URL into components
1726 and apply a full s/// substitution only to the appropriate parts.
1727 .SS "uu encoding and decoding"
1728 .IX Subsection "uu encoding and decoding"
1729 The \f(CW\*(C`u\*(C'\fR template to \f(CWpack()\fR or \f(CWunpack()\fR will render EBCDIC data in
1730 EBCDIC characters equivalent to their ASCII counterparts. For example,
1731 the following will print "Yes indeed\en" on either an ASCII or EBCDIC
1732 computer:
1733 .PP
1734 .Vb 10
1735 \& $all_byte_chrs = \*(Aq\*(Aq;
1736 \& for (0..255) { $all_byte_chrs .= chr($_); }
1737 \& $uuencode_byte_chrs = pack(\*(Aqu\*(Aq, $all_byte_chrs);
1738 \& ($uu = <<\*(AqENDOFHEREDOC\*(Aq) =~ s/^\es*//gm;
1739 \& M\`\`$"\`P0%!@<("0H+#\`T.#Q\`1$A,4%187&!D:&QP=\*(AqA\e@(2(C)"4F)R@I*BLL
1740 \& M+2XO,#$R,S0U\-C<X.3H[/#T^/T!!0D\-$149\*(Aq2$E*2TQ\-3D]045)35%565UA9
1741 \& M6EM<75Y?8&%B8V1E9F=H:6IK;&UN;W!Q<G\-T=79W>\*(AqEZ>WQ]?G^\`@8*#A(6&
1742 \& MAXB)BHN,C8Z/D)&2DY25EI>8F9J;G)V>GZ"AHJ.DI::GJ*FJJZRMKJ^PL;*S
1743 \& MM+6VM[BYNKN\eO;Z_P,\*(Aq"P\e3%QL?(R<K+S,W.S]#1TM/4U=;7V\-G:V]S=WM_@
1744 \& ?X>+CY.7FY^CIZNOL[>[O\e/\*(AqR\e_3U]O?X^?K[_/W^_P\`\`
1745 \& ENDOFHEREDOC
1746 \& if ($uuencode_byte_chrs eq $uu) {
1747 \& print "Yes ";
1748 \& }
1749 \& $uudecode_byte_chrs = unpack(\*(Aqu\*(Aq, $uuencode_byte_chrs);
1750 \& if ($uudecode_byte_chrs eq $all_byte_chrs) {
1751 \& print "indeed\en";
1752 \& }
1753 .Ve
1754 .PP
1755 Here is a very spartan uudecoder that will work on EBCDIC:
1756 .PP
1757 .Vb 10
1758 \& #!/usr/local/bin/perl
1759 \& $_ = <> until ($mode,$file) = /^begin\es*(\ed*)\es*(\eS*)/;
1760 \& open(OUT, "> $file") if $file ne "";
1761 \& while(<>) {
1762 \& last if /^end/;
1763 \& next if /[a\-z]/;
1764 \& next unless int((((utf8::native_to_unicode(ord()) \- 32 ) & 077)
1765 \& + 2) / 3)
1766 \& == int(length() / 4);
1767 \& print OUT unpack("u", $_);
1768 \& }
1769 \& close(OUT);
1770 \& chmod oct($mode), $file;
1771 .Ve
1772 .SS "Quoted-Printable encoding and decoding"
1773 .IX Subsection "Quoted-Printable encoding and decoding"
1774 On ASCII-encoded platforms it is possible to strip characters outside of
1775 the printable set using:
1776 .PP
1777 .Vb 3
1778 \& # This QP encoder works on ASCII only
1779 \& $qp_string =~ s/([=\ex00\-\ex1F\ex80\-\exFF])/
1780 \& sprintf("=%02X",ord($1))/xge;
1781 .Ve
1782 .PP
1783 Starting in Perl v5.22, this is trivially changeable to work portably on
1784 both ASCII and EBCDIC platforms.
1785 .PP
1786 .Vb 3
1787 \& # This QP encoder works on both ASCII and EBCDIC
1788 \& $qp_string =~ s/([=\eN{U+00}\-\eN{U+1F}\eN{U+80}\-\eN{U+FF}])/
1789 \& sprintf("=%02X",ord($1))/xge;
1790 .Ve
1791 .PP
1792 For earlier Perls, a QP encoder that works on both ASCII and EBCDIC
1793 platforms would look somewhat like the following:
1794 .PP
1795 .Vb 4
1796 \& $delete = utf8::unicode_to_native(ord("\ex7F"));
1797 \& $qp_string =~
1798 \& s/([^[:print:]$delete])/
1799 \& sprintf("=%02X",utf8::native_to_unicode(ord($1)))/xage;
1800 .Ve
1801 .PP
1802 (although in production code the substitutions might be done
1803 in the EBCDIC branch with the function call and separately in the
1804 ASCII branch without the expense of the identity map; in Perl v5.22, the
1805 identity map is optimized out so there is no expense, but the
1806 alternative above is simpler and is also available in v5.22).
1807 .PP
1808 Such QP strings can be decoded with:
1809 .PP
1810 .Vb 3
1811 \& # This QP decoder is limited to ASCII only
1812 \& $string =~ s/=([[:xdigit:][[:xdigit:])/chr hex $1/ge;
1813 \& $string =~ s/=[\en\er]+$//;
1814 .Ve
1815 .PP
1816 Whereas a QP decoder that works on both ASCII and EBCDIC platforms
1817 would look somewhat like the following:
1818 .PP
1819 .Vb 3
1820 \& $string =~ s/=([[:xdigit:][:xdigit:]])/
1821 \& chr utf8::native_to_unicode(hex $1)/xge;
1822 \& $string =~ s/=[\en\er]+$//;
1823 .Ve
1824 .SS "Caesarean ciphers"
1825 .IX Subsection "Caesarean ciphers"
1826 The practice of shifting an alphabet one or more characters for encipherment
1827 dates back thousands of years and was explicitly detailed by Gaius Julius
1828 Caesar in his \fBGallic Wars\fR text. A single alphabet shift is sometimes
1829 referred to as a rotation and the shift amount is given as a number \f(CW$n\fR after
1830 the string 'rot' or "rot$n". Rot0 and rot26 would designate identity maps
1831 on the 26\-letter English version of the Latin alphabet. Rot13 has the
1832 interesting property that alternate subsequent invocations are identity maps
1833 (thus rot13 is its own non-trivial inverse in the group of 26 alphabet
1834 rotations). Hence the following is a rot13 encoder and decoder that will
1835 work on ASCII and EBCDIC platforms:
1836 .PP
1837 .Vb 1
1838 \& #!/usr/local/bin/perl
1839 \&
1840 \& while(<>){
1841 \& tr/n\-za\-mN\-ZA\-M/a\-zA\-Z/;
1842 \& print;
1843 \& }
1844 .Ve
1845 .PP
1846 In one-liner form:
1847 .PP
1848 .Vb 1
1849 \& perl \-ne \*(Aqtr/n\-za\-mN\-ZA\-M/a\-zA\-Z/;print\*(Aq
1850 .Ve
1851 .SH "Hashing order and checksums"
1852 .IX Header "Hashing order and checksums"
1853 Perl deliberately randomizes hash order for security purposes on both
1854 ASCII and EBCDIC platforms.
1855 .PP
1856 EBCDIC checksums will differ for the same file translated into ASCII
1857 and vice versa.
1858 .SH "I18N AND L10N"
1859 .IX Header "I18N AND L10N"
1860 Internationalization (I18N) and localization (L10N) are supported at least
1861 in principle even on EBCDIC platforms. The details are system-dependent
1862 and discussed under the "OS ISSUES" section below.
1863 .SH "MULTI-OCTET CHARACTER SETS"
1864 .IX Header "MULTI-OCTET CHARACTER SETS"
1865 Perl works with UTF-EBCDIC, a multi-byte encoding. In Perls earlier
1866 than v5.22, there may be various bugs in this regard.
1867 .PP
1868 Legacy multi byte EBCDIC code pages XXX.
1869 .SH "OS ISSUES"
1870 .IX Header "OS ISSUES"
1871 There may be a few system-dependent issues
1872 of concern to EBCDIC Perl programmers.
1873 .SS OS/400
1874 .IX Subsection "OS/400"
1875 .IP PASE 8
1876 .IX Item "PASE"
1877 The PASE environment is a runtime environment for OS/400 that can run
1878 executables built for PowerPC AIX in OS/400; see perlos400. PASE
1879 is ASCII-based, not EBCDIC-based as the ILE.
1880 .IP "IFS access" 8
1881 .IX Item "IFS access"
1882 XXX.
1883 .SS "OS/390, z/OS"
1884 .IX Subsection "OS/390, z/OS"
1885 Perl runs under Unix Systems Services or USS.
1886 .ie n .IP """sigaction""" 8
1887 .el .IP \f(CWsigaction\fR 8
1888 .IX Item "sigaction"
1889 \&\f(CW\*(C`SA_SIGINFO\*(C'\fR can have segmentation faults.
1890 .ie n .IP """chcp""" 8
1891 .el .IP \f(CWchcp\fR 8
1892 .IX Item "chcp"
1893 \&\fBchcp\fR is supported as a shell utility for displaying and changing
1894 one's code page. See also \fBchcp\fR\|(1).
1895 .IP "dataset access" 8
1896 .IX Item "dataset access"
1897 For sequential data set access try:
1898 .Sp
1899 .Vb 1
1900 \& my @ds_records = \`cat //DSNAME\`;
1901 .Ve
1902 .Sp
1903 or:
1904 .Sp
1905 .Vb 1
1906 \& my @ds_records = \`cat //\*(AqHLQ.DSNAME\*(Aq\`;
1907 .Ve
1908 .Sp
1909 See also the OS390::Stdio module on CPAN.
1910 .ie n .IP """iconv""" 8
1911 .el .IP \f(CWiconv\fR 8
1912 .IX Item "iconv"
1913 \&\fBiconv\fR is supported as both a shell utility and a C RTL routine.
1914 See also the \fBiconv\fR\|(1) and \fBiconv\fR\|(3) manual pages.
1915 .IP locales 8
1916 .IX Item "locales"
1917 Locales are supported. There may be glitches when a locale is another
1918 EBCDIC code page which has some of the
1919 code-page variant characters in other
1920 positions.
1921 .Sp
1922 There aren't currently any real UTF\-8 locales, even though some locale
1923 names contain the string "UTF\-8".
1924 .Sp
1925 See perllocale for information on locales. The L10N files
1926 are in \fI/usr/nls/locale\fR. \f(CW$Config{d_setlocale}\fR is \f(CW\*(Aqdefine\*(Aq\fR on
1927 OS/390 or z/OS.
1928 .SS POSIX-BC?
1929 .IX Subsection "POSIX-BC?"
1930 XXX.
1931 .SH BUGS
1932 .IX Header "BUGS"
1933 .IP \(bu 4
1934 Not all shells will allow multiple \f(CW\*(C`\-e\*(C'\fR string arguments to perl to
1935 be concatenated together properly as recipes in this document
1936 0, 2, 4, 5, and 6 might
1937 seem to imply.
1938 .IP \(bu 4
1939 There are a significant number of test failures in the CPAN modules
1940 shipped with Perl v5.22 and 5.24. These are only in modules not primarily
1941 maintained by Perl 5 porters. Some of these are failures in the tests
1942 only: they don't realize that it is proper to get different results on
1943 EBCDIC platforms. And some of the failures are real bugs. If you
1944 compile and do a \f(CW\*(C`make test\*(C'\fR on Perl, all tests on the \f(CW\*(C`/cpan\*(C'\fR
1945 directory are skipped.
1946 .Sp
1947 Encode partially works.
1948 .IP \(bu 4
1949 In earlier Perl versions, when byte and character data were
1950 concatenated, the new string was sometimes created by
1951 decoding the byte strings as \fIISO 8859\-1 (Latin\-1)\fR, even if the
1952 old Unicode string used EBCDIC.
1953 .SH "SEE ALSO"
1954 .IX Header "SEE ALSO"
1955 perllocale, perlfunc, perlunicode, utf8.
1956 .SH REFERENCES
1957 .IX Header "REFERENCES"
1958 <http://std.dkuug.dk/i18n/charmaps>
1959 .PP
1960 <https://www.unicode.org/>
1961 .PP
1962 <https://www.unicode.org/reports/tr16/>
1963 .PP
1964 <https://www.sr\-ix.com/Archive/CharCodeHist/index.html>
1965 \&\fBASCII: American Standard Code for Information Infiltration\fR Tom Jennings,
1966 September 1999.
1967 .PP
1968 \&\fBThe Unicode Standard, Version 3.0\fR The Unicode Consortium, Lisa Moore ed.,
1969 ISBN 0\-201\-61633\-5, Addison Wesley Developers Press, February 2000.
1970 .PP
1971 \&\fBCDRA: IBM \- Character Data Representation Architecture \-
1972 Reference and Registry\fR, IBM SC09\-2190\-00, December 1996.
1973 .PP
1974 "Demystifying Character Sets", Andrea Vine, Multilingual Computing
1975 & Technology, \fB#26 Vol. 10 Issue 4\fR, August/September 1999;
1976 ISSN 1523\-0309; Multilingual Computing Inc. Sandpoint ID, USA.
1977 .PP
1978 \&\fBCodes, Ciphers, and Other Cryptic and Clandestine Communication\fR
1979 Fred B. Wrixon, ISBN 1\-57912\-040\-7, Black Dog & Leventhal Publishers,
1980 1998.
1981 .PP
1982 <http://www.bobbemer.com/P\-BIT.HTM>
1983 \&\fBIBM \- EBCDIC and the P\-bit; The biggest Computer Goof Ever\fR Robert Bemer.
1984 .SH HISTORY
1985 .IX Header "HISTORY"
1986 15 April 2001: added UTF\-8 and UTF-EBCDIC to main table, pvhp.
1987 .SH AUTHOR
1988 .IX Header "AUTHOR"
1989 Peter Prymmer [email protected] wrote this in 1999 and 2000
1990 with CCSID 0819 and 0037 help from Chris Leach and
1991 André Pirard [email protected] as well as POSIX-BC
1992 help from Thomas Dorner [email protected].
1993 Thanks also to Vickie Cooper, Philip Newton, William Raffloer, and
1994 Joe Smith. Trademarks, registered trademarks, service marks and
1995 registered service marks used in this document are the property of
1996 their respective owners.
1997 .PP
1998 Now maintained by Perl5 Porters.