1PERLEBCDIC(1) Perl Programmers Reference Guide PERLEBCDIC(1)
2
3
4
6 perlebcdic - Considerations for running Perl on EBCDIC platforms
7
9 An exploration of some of the issues facing Perl programmers on EBCDIC
10 based computers.
11
12 Portions of this document that are still incomplete are marked with
13 XXX.
14
15 Early Perl versions worked on some EBCDIC machines, but the last known
16 version that ran on EBCDIC was v5.8.7, until v5.22, when the Perl core
17 again works on z/OS. Theoretically, it could work on OS/400 or
18 Siemens' BS2000 (or their successors), but this is untested. In v5.22
19 and 5.24, not all the modules found on CPAN but shipped with core Perl
20 work on z/OS.
21
22 If you want to use Perl on a non-z/OS EBCDIC machine, please let us
23 know at <https://github.com/Perl/perl5/issues>.
24
25 Writing Perl on an EBCDIC platform is really no different than writing
26 on an "ASCII" one, but with different underlying numbers, as we'll see
27 shortly. You'll have to know something about those "ASCII" platforms
28 because the documentation is biased and will frequently use example
29 numbers that don't apply to EBCDIC. There are also very few CPAN
30 modules that are written for EBCDIC and which don't work on ASCII;
31 instead the vast majority of CPAN modules are written for ASCII, and
32 some may happen to work on EBCDIC, while a few have been designed to
33 portably work on both.
34
35 If your code just uses the 52 letters A-Z and a-z, plus SPACE, the
36 digits 0-9, and the punctuation characters that Perl uses, plus a few
37 controls that are denoted by escape sequences like "\n" and "\t", then
38 there's nothing special about using Perl, and your code may very well
39 work on an ASCII machine without change.
40
41 But if you write code that uses "\005" to mean a TAB or "\xC1" to mean
42 an "A", or "\xDF" to mean a "ye" (small "y" with a diaeresis), then
43 your code may well work on your EBCDIC platform, but not on an ASCII
44 one. That's fine to do if no one will ever want to run your code on an
45 ASCII platform; but the bias in this document will be towards writing
46 code portable between EBCDIC and ASCII systems. Again, if every
47 character you care about is easily enterable from your keyboard, you
48 don't have to know anything about ASCII, but many keyboards don't
49 easily allow you to directly enter, say, the character "\xDF", so you
50 have to specify it indirectly, such as by using the "\xDF" escape
51 sequence. In those cases it's easiest to know something about the
52 ASCII/Unicode character sets. If you know that the small "ye" is
53 "U+00FF", then you can instead specify it as "\N{U+FF}", and have the
54 computer automatically translate it to "\xDF" on your platform, and
55 leave it as "\xFF" on ASCII ones. Or you could specify it by name,
56 "\N{LATIN SMALL LETTER Y WITH DIAERESIS" and not have to know the
57 numbers. Either way works, but both require familiarity with Unicode.
58
60 ASCII
61 The American Standard Code for Information Interchange (ASCII or US-
62 ASCII) is a set of integers running from 0 to 127 (decimal) that have
63 standardized interpretations by the computers which use ASCII. For
64 example, 65 means the letter "A". The range 0..127 can be covered by
65 setting various bits in a 7-bit binary digit, hence the set is
66 sometimes referred to as "7-bit ASCII". ASCII was described by the
67 American National Standards Institute document ANSI X3.4-1986. It was
68 also described by ISO 646:1991 (with localization for currency
69 symbols). The full ASCII set is given in the table below as the first
70 128 elements. Languages that can be written adequately with the
71 characters in ASCII include English, Hawaiian, Indonesian, Swahili and
72 some Native American languages.
73
74 Most non-EBCDIC character sets are supersets of ASCII. That is the
75 integers 0-127 mean what ASCII says they mean. But integers 128 and
76 above are specific to the character set.
77
78 Many of these fit entirely into 8 bits, using ASCII as 0-127, while
79 specifying what 128-255 mean, and not using anything above 255. Thus,
80 these are single-byte (or octet if you prefer) character sets. One
81 important one (since Unicode is a superset of it) is the ISO 8859-1
82 character set.
83
84 ISO 8859
85 The ISO 8859-$n are a collection of character code sets from the
86 International Organization for Standardization (ISO), each of which
87 adds characters to the ASCII set that are typically found in various
88 languages, many of which are based on the Roman, or Latin, alphabet.
89 Most are for European languages, but there are also ones for Arabic,
90 Greek, Hebrew, and Thai. There are good references on the web about
91 all these.
92
93 Latin 1 (ISO 8859-1)
94 A particular 8-bit extension to ASCII that includes grave and acute
95 accented Latin characters. Languages that can employ ISO 8859-1
96 include all the languages covered by ASCII as well as Afrikaans,
97 Albanian, Basque, Catalan, Danish, Faroese, Finnish, Norwegian,
98 Portuguese, Spanish, and Swedish. Dutch is covered albeit without the
99 ij ligature. French is covered too but without the oe ligature.
100 German can use ISO 8859-1 but must do so without German-style quotation
101 marks. This set is based on Western European extensions to ASCII and
102 is commonly encountered in world wide web work. In IBM character code
103 set identification terminology, ISO 8859-1 is also known as CCSID 819
104 (or sometimes 0819 or even 00819).
105
106 EBCDIC
107 The Extended Binary Coded Decimal Interchange Code refers to a large
108 collection of single- and multi-byte coded character sets that are
109 quite different from ASCII and ISO 8859-1, and are all slightly
110 different from each other; they typically run on host computers. The
111 EBCDIC encodings derive from 8-bit byte extensions of Hollerith punched
112 card encodings, which long predate ASCII. The layout on the cards was
113 such that high bits were set for the upper and lower case alphabetic
114 characters "[a-z]" and "[A-Z]", but there were gaps within each Latin
115 alphabet range, visible in the table below. These gaps can cause
116 complications.
117
118 Some IBM EBCDIC character sets may be known by character code set
119 identification numbers (CCSID numbers) or code page numbers.
120
121 Perl can be compiled on platforms that run any of three commonly used
122 EBCDIC character sets, listed below.
123
124 The 13 variant characters
125
126 Among IBM EBCDIC character code sets there are 13 characters that are
127 often mapped to different integer values. Those characters are known
128 as the 13 "variant" characters and are:
129
130 \ [ ] { } ^ ~ ! # | $ @ `
131
132 When Perl is compiled for a platform, it looks at all of these
133 characters to guess which EBCDIC character set the platform uses, and
134 adapts itself accordingly to that platform. If the platform uses a
135 character set that is not one of the three Perl knows about, Perl will
136 either fail to compile, or mistakenly and silently choose one of the
137 three.
138
139 The Line Feed (LF) character is actually a 14th variant character, and
140 Perl checks for that as well.
141
142 EBCDIC code sets recognized by Perl
143
144 0037
145 Character code set ID 0037 is a mapping of the ASCII plus Latin-1
146 characters (i.e. ISO 8859-1) to an EBCDIC set. 0037 is used in
147 North American English locales on the OS/400 operating system that
148 runs on AS/400 computers. CCSID 0037 differs from ISO 8859-1 in
149 236 places; in other words they agree on only 20 code point values.
150
151 1047
152 Character code set ID 1047 is also a mapping of the ASCII plus
153 Latin-1 characters (i.e. ISO 8859-1) to an EBCDIC set. 1047 is
154 used under Unix System Services for OS/390 or z/OS, and OpenEdition
155 for VM/ESA. CCSID 1047 differs from CCSID 0037 in eight places,
156 and from ISO 8859-1 in 236.
157
158 POSIX-BC
159 The EBCDIC code page in use on Siemens' BS2000 system is distinct
160 from 1047 and 0037. It is identified below as the POSIX-BC set.
161 Like 0037 and 1047, it is the same as ISO 8859-1 in 20 code point
162 values.
163
164 Unicode code points versus EBCDIC code points
165 In Unicode terminology a code point is the number assigned to a
166 character: for example, in EBCDIC the character "A" is usually assigned
167 the number 193. In Unicode, the character "A" is assigned the number
168 65. All the code points in ASCII and Latin-1 (ISO 8859-1) have the
169 same meaning in Unicode. All three of the recognized EBCDIC code sets
170 have 256 code points, and in each code set, all 256 code points are
171 mapped to equivalent Latin1 code points. Obviously, "A" will map to
172 "A", "B" => "B", "%" => "%", etc., for all printable characters in
173 Latin1 and these code pages.
174
175 It also turns out that EBCDIC has nearly precise equivalents for the
176 ASCII/Latin1 C0 controls and the DELETE control. (The C0 controls are
177 those whose ASCII code points are 0..0x1F; things like TAB, ACK, BEL,
178 etc.) A mapping is set up between these ASCII/EBCDIC controls. There
179 isn't such a precise mapping between the C1 controls on ASCII platforms
180 and the remaining EBCDIC controls. What has been done is to map these
181 controls, mostly arbitrarily, to some otherwise unmatched character in
182 the other character set. Most of these are very very rarely used
183 nowadays in EBCDIC anyway, and their names have been dropped, without
184 much complaint. For example the EO (Eight Ones) EBCDIC control
185 (consisting of eight one bits = 0xFF) is mapped to the C1 APC control
186 (0x9F), and you can't use the name "EO".
187
188 The EBCDIC controls provide three possible line terminator characters,
189 CR (0x0D), LF (0x25), and NL (0x15). On ASCII platforms, the symbols
190 "NL" and "LF" refer to the same character, but in strict EBCDIC
191 terminology they are different ones. The EBCDIC NL is mapped to the C1
192 control called "NEL" ("Next Line"; here's a case where the mapping
193 makes quite a bit of sense, and hence isn't just arbitrary). On some
194 EBCDIC platforms, this NL or NEL is the typical line terminator. This
195 is true of z/OS and BS2000. In these platforms, the C compilers will
196 swap the LF and NEL code points, so that "\n" is 0x15, and refers to
197 NL. Perl does that too; you can see it in the code chart below. This
198 makes things generally "just work" without you even having to be aware
199 that there is a swap.
200
201 Unicode and UTF
202 UTF stands for "Unicode Transformation Format". UTF-8 is an encoding
203 of Unicode into a sequence of 8-bit byte chunks, based on ASCII and
204 Latin-1. The length of a sequence required to represent a Unicode code
205 point depends on the ordinal number of that code point, with larger
206 numbers requiring more bytes. UTF-EBCDIC is like UTF-8, but based on
207 EBCDIC. They are enough alike that often, casual usage will conflate
208 the two terms, and use "UTF-8" to mean both the UTF-8 found on ASCII
209 platforms, and the UTF-EBCDIC found on EBCDIC ones.
210
211 You may see the term "invariant" character or code point. This simply
212 means that the character has the same numeric value and representation
213 when encoded in UTF-8 (or UTF-EBCDIC) as when not. (Note that this is
214 a very different concept from "The 13 variant characters" mentioned
215 above. Careful prose will use the term "UTF-8 invariant" instead of
216 just "invariant", but most often you'll see just "invariant".) For
217 example, the ordinal value of "A" is 193 in most EBCDIC code pages, and
218 also is 193 when encoded in UTF-EBCDIC. All UTF-8 (or UTF-EBCDIC)
219 variant code points occupy at least two bytes when encoded in UTF-8 (or
220 UTF-EBCDIC); by definition, the UTF-8 (or UTF-EBCDIC) invariant code
221 points are exactly one byte whether encoded in UTF-8 (or UTF-EBCDIC),
222 or not. (By now you see why people typically just say "UTF-8" when
223 they also mean "UTF-EBCDIC". For the rest of this document, we'll
224 mostly be casual about it too.) In ASCII UTF-8, the code points
225 corresponding to the lowest 128 ordinal numbers (0 - 127: the ASCII
226 characters) are invariant. In UTF-EBCDIC, there are 160 invariant
227 characters. (If you care, the EBCDIC invariants are those characters
228 which have ASCII equivalents, plus those that correspond to the C1
229 controls (128 - 159 on ASCII platforms).)
230
231 A string encoded in UTF-EBCDIC may be longer (very rarely shorter) than
232 one encoded in UTF-8. Perl extends both UTF-8 and UTF-EBCDIC so that
233 they can encode code points above the Unicode maximum of U+10FFFF.
234 Both extensions are constructed to allow encoding of any code point
235 that fits in a 64-bit word.
236
237 UTF-EBCDIC is defined by Unicode Technical Report #16
238 <https://www.unicode.org/reports/tr16> (often referred to as just
239 TR16). It is defined based on CCSID 1047, not allowing for the
240 differences for other code pages. This allows for easy interchange of
241 text between computers running different code pages, but makes it
242 unusable, without adaptation, for Perl on those other code pages.
243
244 The reason for this unusability is that a fundamental assumption of
245 Perl is that the characters it cares about for parsing and lexical
246 analysis are the same whether or not the text is in UTF-8. For
247 example, Perl expects the character "[" to have the same
248 representation, no matter if the string containing it (or program text)
249 is UTF-8 encoded or not. To ensure this, Perl adapts UTF-EBCDIC to the
250 particular code page so that all characters it expects to be UTF-8
251 invariant are in fact UTF-8 invariant. This means that text generated
252 on a computer running one version of Perl's UTF-EBCDIC has to be
253 translated to be intelligible to a computer running another.
254
255 TR16 implies a method to extend UTF-EBCDIC to encode points up through
256 "2 ** 31 - 1". Perl uses this method for code points up through
257 "2 ** 30 - 1", but uses an incompatible method for larger ones, to
258 enable it to handle much larger code points than otherwise.
259
260 Using Encode
261 Starting from Perl 5.8 you can use the standard module Encode to
262 translate from EBCDIC to Latin-1 code points. Encode knows about more
263 EBCDIC character sets than Perl can currently be compiled to run on.
264
265 use Encode 'from_to';
266
267 my %ebcdic = ( 176 => 'cp37', 95 => 'cp1047', 106 => 'posix-bc' );
268
269 # $a is in EBCDIC code points
270 from_to($a, $ebcdic{ord '^'}, 'latin1');
271 # $a is ISO 8859-1 code points
272
273 and from Latin-1 code points to EBCDIC code points
274
275 use Encode 'from_to';
276
277 my %ebcdic = ( 176 => 'cp37', 95 => 'cp1047', 106 => 'posix-bc' );
278
279 # $a is ISO 8859-1 code points
280 from_to($a, 'latin1', $ebcdic{ord '^'});
281 # $a is in EBCDIC code points
282
283 For doing I/O it is suggested that you use the autotranslating features
284 of PerlIO, see perluniintro.
285
286 Since version 5.8 Perl uses the PerlIO I/O library. This enables you
287 to use different encodings per IO channel. For example you may use
288
289 use Encode;
290 open($f, ">:encoding(ascii)", "test.ascii");
291 print $f "Hello World!\n";
292 open($f, ">:encoding(cp37)", "test.ebcdic");
293 print $f "Hello World!\n";
294 open($f, ">:encoding(latin1)", "test.latin1");
295 print $f "Hello World!\n";
296 open($f, ">:encoding(utf8)", "test.utf8");
297 print $f "Hello World!\n";
298
299 to get four files containing "Hello World!\n" in ASCII, CP 0037 EBCDIC,
300 ISO 8859-1 (Latin-1) (in this example identical to ASCII since only
301 ASCII characters were printed), and UTF-EBCDIC (in this example
302 identical to normal EBCDIC since only characters that don't differ
303 between EBCDIC and UTF-EBCDIC were printed). See the documentation of
304 Encode::PerlIO for details.
305
306 As the PerlIO layer uses raw IO (bytes) internally, all this totally
307 ignores things like the type of your filesystem (ASCII or EBCDIC).
308
310 The following tables list the ASCII and Latin 1 ordered sets including
311 the subsets: C0 controls (0..31), ASCII graphics (32..7e), delete (7f),
312 C1 controls (80..9f), and Latin-1 (a.k.a. ISO 8859-1) (a0..ff). In the
313 table names of the Latin 1 extensions to ASCII have been labelled with
314 character names roughly corresponding to The Unicode Standard, Version
315 6.1 albeit with substitutions such as "s/LATIN//" and "s/VULGAR//" in
316 all cases; "s/CAPITAL LETTER//" in some cases; and
317 "s/SMALL LETTER ([A-Z])/\l$1/" in some other cases. Controls are
318 listed using their Unicode 6.2 abbreviations. The differences between
319 the 0037 and 1047 sets are flagged with "**". The differences between
320 the 1047 and POSIX-BC sets are flagged with "##." All "ord()" numbers
321 listed are decimal. If you would rather see this table listing octal
322 values, then run the table (that is, the pod source text of this
323 document, since this recipe may not work with a pod2_other_format
324 translation) through:
325
326 recipe 0
327
328 perl -ne 'if(/(.{29})(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/)' \
329 -e '{printf("%s%-5.03o%-5.03o%-5.03o%.03o\n",$1,$2,$3,$4,$5)}' \
330 perlebcdic.pod
331
332 If you want to retain the UTF-x code points then in script form you
333 might want to write:
334
335 recipe 1
336
337 open(FH,"<perlebcdic.pod") or die "Could not open perlebcdic.pod: $!";
338 while (<FH>) {
339 if (/(.{29})(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\.?(\d*)
340 \s+(\d+)\.?(\d*)/x)
341 {
342 if ($7 ne '' && $9 ne '') {
343 printf(
344 "%s%-5.03o%-5.03o%-5.03o%-5.03o%-3o.%-5o%-3o.%.03o\n",
345 $1,$2,$3,$4,$5,$6,$7,$8,$9);
346 }
347 elsif ($7 ne '') {
348 printf("%s%-5.03o%-5.03o%-5.03o%-5.03o%-3o.%-5o%.03o\n",
349 $1,$2,$3,$4,$5,$6,$7,$8);
350 }
351 else {
352 printf("%s%-5.03o%-5.03o%-5.03o%-5.03o%-5.03o%.03o\n",
353 $1,$2,$3,$4,$5,$6,$8);
354 }
355 }
356 }
357
358 If you would rather see this table listing hexadecimal values then run
359 the table through:
360
361 recipe 2
362
363 perl -ne 'if(/(.{29})(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/)' \
364 -e '{printf("%s%-5.02X%-5.02X%-5.02X%.02X\n",$1,$2,$3,$4,$5)}' \
365 perlebcdic.pod
366
367 Or, in order to retain the UTF-x code points in hexadecimal:
368
369 recipe 3
370
371 open(FH,"<perlebcdic.pod") or die "Could not open perlebcdic.pod: $!";
372 while (<FH>) {
373 if (/(.{29})(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\.?(\d*)
374 \s+(\d+)\.?(\d*)/x)
375 {
376 if ($7 ne '' && $9 ne '') {
377 printf(
378 "%s%-5.02X%-5.02X%-5.02X%-5.02X%-2X.%-6.02X%02X.%02X\n",
379 $1,$2,$3,$4,$5,$6,$7,$8,$9);
380 }
381 elsif ($7 ne '') {
382 printf("%s%-5.02X%-5.02X%-5.02X%-5.02X%-2X.%-6.02X%02X\n",
383 $1,$2,$3,$4,$5,$6,$7,$8);
384 }
385 else {
386 printf("%s%-5.02X%-5.02X%-5.02X%-5.02X%-5.02X%02X\n",
387 $1,$2,$3,$4,$5,$6,$8);
388 }
389 }
390 }
391
392
393 ISO
394 8859-1 POS- CCSID
395 CCSID CCSID CCSID IX- 1047
396 chr 0819 0037 1047 BC UTF-8 UTF-EBCDIC
397 ---------------------------------------------------------------------
398 <NUL> 0 0 0 0 0 0
399 <SOH> 1 1 1 1 1 1
400 <STX> 2 2 2 2 2 2
401 <ETX> 3 3 3 3 3 3
402 <EOT> 4 55 55 55 4 55
403 <ENQ> 5 45 45 45 5 45
404 <ACK> 6 46 46 46 6 46
405 <BEL> 7 47 47 47 7 47
406 <BS> 8 22 22 22 8 22
407 <HT> 9 5 5 5 9 5
408 <LF> 10 37 21 21 10 21 **
409 <VT> 11 11 11 11 11 11
410 <FF> 12 12 12 12 12 12
411 <CR> 13 13 13 13 13 13
412 <SO> 14 14 14 14 14 14
413 <SI> 15 15 15 15 15 15
414 <DLE> 16 16 16 16 16 16
415 <DC1> 17 17 17 17 17 17
416 <DC2> 18 18 18 18 18 18
417 <DC3> 19 19 19 19 19 19
418 <DC4> 20 60 60 60 20 60
419 <NAK> 21 61 61 61 21 61
420 <SYN> 22 50 50 50 22 50
421 <ETB> 23 38 38 38 23 38
422 <CAN> 24 24 24 24 24 24
423 <EOM> 25 25 25 25 25 25
424 <SUB> 26 63 63 63 26 63
425 <ESC> 27 39 39 39 27 39
426 <FS> 28 28 28 28 28 28
427 <GS> 29 29 29 29 29 29
428 <RS> 30 30 30 30 30 30
429 <US> 31 31 31 31 31 31
430 <SPACE> 32 64 64 64 32 64
431 ! 33 90 90 90 33 90
432 " 34 127 127 127 34 127
433 # 35 123 123 123 35 123
434 $ 36 91 91 91 36 91
435 % 37 108 108 108 37 108
436 & 38 80 80 80 38 80
437 ' 39 125 125 125 39 125
438 ( 40 77 77 77 40 77
439 ) 41 93 93 93 41 93
440 * 42 92 92 92 42 92
441 + 43 78 78 78 43 78
442 , 44 107 107 107 44 107
443 - 45 96 96 96 45 96
444 . 46 75 75 75 46 75
445 / 47 97 97 97 47 97
446 0 48 240 240 240 48 240
447 1 49 241 241 241 49 241
448 2 50 242 242 242 50 242
449 3 51 243 243 243 51 243
450 4 52 244 244 244 52 244
451 5 53 245 245 245 53 245
452 6 54 246 246 246 54 246
453 7 55 247 247 247 55 247
454 8 56 248 248 248 56 248
455 9 57 249 249 249 57 249
456 : 58 122 122 122 58 122
457 ; 59 94 94 94 59 94
458 < 60 76 76 76 60 76
459 = 61 126 126 126 61 126
460 > 62 110 110 110 62 110
461 ? 63 111 111 111 63 111
462 @ 64 124 124 124 64 124
463 A 65 193 193 193 65 193
464 B 66 194 194 194 66 194
465 C 67 195 195 195 67 195
466 D 68 196 196 196 68 196
467 E 69 197 197 197 69 197
468 F 70 198 198 198 70 198
469 G 71 199 199 199 71 199
470 H 72 200 200 200 72 200
471 I 73 201 201 201 73 201
472 J 74 209 209 209 74 209
473 K 75 210 210 210 75 210
474 L 76 211 211 211 76 211
475 M 77 212 212 212 77 212
476 N 78 213 213 213 78 213
477 O 79 214 214 214 79 214
478 P 80 215 215 215 80 215
479 Q 81 216 216 216 81 216
480 R 82 217 217 217 82 217
481 S 83 226 226 226 83 226
482 T 84 227 227 227 84 227
483 U 85 228 228 228 85 228
484 V 86 229 229 229 86 229
485 W 87 230 230 230 87 230
486 X 88 231 231 231 88 231
487 Y 89 232 232 232 89 232
488 Z 90 233 233 233 90 233
489 [ 91 186 173 187 91 173 ** ##
490 \ 92 224 224 188 92 224 ##
491 ] 93 187 189 189 93 189 **
492 ^ 94 176 95 106 94 95 ** ##
493 _ 95 109 109 109 95 109
494 ` 96 121 121 74 96 121 ##
495 a 97 129 129 129 97 129
496 b 98 130 130 130 98 130
497 c 99 131 131 131 99 131
498 d 100 132 132 132 100 132
499 e 101 133 133 133 101 133
500 f 102 134 134 134 102 134
501 g 103 135 135 135 103 135
502 h 104 136 136 136 104 136
503 i 105 137 137 137 105 137
504 j 106 145 145 145 106 145
505 k 107 146 146 146 107 146
506 l 108 147 147 147 108 147
507 m 109 148 148 148 109 148
508 n 110 149 149 149 110 149
509 o 111 150 150 150 111 150
510 p 112 151 151 151 112 151
511 q 113 152 152 152 113 152
512 r 114 153 153 153 114 153
513 s 115 162 162 162 115 162
514 t 116 163 163 163 116 163
515 u 117 164 164 164 117 164
516 v 118 165 165 165 118 165
517 w 119 166 166 166 119 166
518 x 120 167 167 167 120 167
519 y 121 168 168 168 121 168
520 z 122 169 169 169 122 169
521 { 123 192 192 251 123 192 ##
522 | 124 79 79 79 124 79
523 } 125 208 208 253 125 208 ##
524 ~ 126 161 161 255 126 161 ##
525 <DEL> 127 7 7 7 127 7
526 <PAD> 128 32 32 32 194.128 32
527 <HOP> 129 33 33 33 194.129 33
528 <BPH> 130 34 34 34 194.130 34
529 <NBH> 131 35 35 35 194.131 35
530 <IND> 132 36 36 36 194.132 36
531 <NEL> 133 21 37 37 194.133 37 **
532 <SSA> 134 6 6 6 194.134 6
533 <ESA> 135 23 23 23 194.135 23
534 <HTS> 136 40 40 40 194.136 40
535 <HTJ> 137 41 41 41 194.137 41
536 <VTS> 138 42 42 42 194.138 42
537 <PLD> 139 43 43 43 194.139 43
538 <PLU> 140 44 44 44 194.140 44
539 <RI> 141 9 9 9 194.141 9
540 <SS2> 142 10 10 10 194.142 10
541 <SS3> 143 27 27 27 194.143 27
542 <DCS> 144 48 48 48 194.144 48
543 <PU1> 145 49 49 49 194.145 49
544 <PU2> 146 26 26 26 194.146 26
545 <STS> 147 51 51 51 194.147 51
546 <CCH> 148 52 52 52 194.148 52
547 <MW> 149 53 53 53 194.149 53
548 <SPA> 150 54 54 54 194.150 54
549 <EPA> 151 8 8 8 194.151 8
550 <SOS> 152 56 56 56 194.152 56
551 <SGC> 153 57 57 57 194.153 57
552 <SCI> 154 58 58 58 194.154 58
553 <CSI> 155 59 59 59 194.155 59
554 <ST> 156 4 4 4 194.156 4
555 <OSC> 157 20 20 20 194.157 20
556 <PM> 158 62 62 62 194.158 62
557 <APC> 159 255 255 95 194.159 255 ##
558 <NON-BREAKING SPACE> 160 65 65 65 194.160 128.65
559 <INVERTED "!" > 161 170 170 170 194.161 128.66
560 <CENT SIGN> 162 74 74 176 194.162 128.67 ##
561 <POUND SIGN> 163 177 177 177 194.163 128.68
562 <CURRENCY SIGN> 164 159 159 159 194.164 128.69
563 <YEN SIGN> 165 178 178 178 194.165 128.70
564 <BROKEN BAR> 166 106 106 208 194.166 128.71 ##
565 <SECTION SIGN> 167 181 181 181 194.167 128.72
566 <DIAERESIS> 168 189 187 121 194.168 128.73 ** ##
567 <COPYRIGHT SIGN> 169 180 180 180 194.169 128.74
568 <FEMININE ORDINAL> 170 154 154 154 194.170 128.81
569 <LEFT POINTING GUILLEMET> 171 138 138 138 194.171 128.82
570 <NOT SIGN> 172 95 176 186 194.172 128.83 ** ##
571 <SOFT HYPHEN> 173 202 202 202 194.173 128.84
572 <REGISTERED TRADE MARK> 174 175 175 175 194.174 128.85
573 <MACRON> 175 188 188 161 194.175 128.86 ##
574 <DEGREE SIGN> 176 144 144 144 194.176 128.87
575 <PLUS-OR-MINUS SIGN> 177 143 143 143 194.177 128.88
576 <SUPERSCRIPT TWO> 178 234 234 234 194.178 128.89
577 <SUPERSCRIPT THREE> 179 250 250 250 194.179 128.98
578 <ACUTE ACCENT> 180 190 190 190 194.180 128.99
579 <MICRO SIGN> 181 160 160 160 194.181 128.100
580 <PARAGRAPH SIGN> 182 182 182 182 194.182 128.101
581 <MIDDLE DOT> 183 179 179 179 194.183 128.102
582 <CEDILLA> 184 157 157 157 194.184 128.103
583 <SUPERSCRIPT ONE> 185 218 218 218 194.185 128.104
584 <MASC. ORDINAL INDICATOR> 186 155 155 155 194.186 128.105
585 <RIGHT POINTING GUILLEMET> 187 139 139 139 194.187 128.106
586 <FRACTION ONE QUARTER> 188 183 183 183 194.188 128.112
587 <FRACTION ONE HALF> 189 184 184 184 194.189 128.113
588 <FRACTION THREE QUARTERS> 190 185 185 185 194.190 128.114
589 <INVERTED QUESTION MARK> 191 171 171 171 194.191 128.115
590 <A WITH GRAVE> 192 100 100 100 195.128 138.65
591 <A WITH ACUTE> 193 101 101 101 195.129 138.66
592 <A WITH CIRCUMFLEX> 194 98 98 98 195.130 138.67
593 <A WITH TILDE> 195 102 102 102 195.131 138.68
594 <A WITH DIAERESIS> 196 99 99 99 195.132 138.69
595 <A WITH RING ABOVE> 197 103 103 103 195.133 138.70
596 <CAPITAL LIGATURE AE> 198 158 158 158 195.134 138.71
597 <C WITH CEDILLA> 199 104 104 104 195.135 138.72
598 <E WITH GRAVE> 200 116 116 116 195.136 138.73
599 <E WITH ACUTE> 201 113 113 113 195.137 138.74
600 <E WITH CIRCUMFLEX> 202 114 114 114 195.138 138.81
601 <E WITH DIAERESIS> 203 115 115 115 195.139 138.82
602 <I WITH GRAVE> 204 120 120 120 195.140 138.83
603 <I WITH ACUTE> 205 117 117 117 195.141 138.84
604 <I WITH CIRCUMFLEX> 206 118 118 118 195.142 138.85
605 <I WITH DIAERESIS> 207 119 119 119 195.143 138.86
606 <CAPITAL LETTER ETH> 208 172 172 172 195.144 138.87
607 <N WITH TILDE> 209 105 105 105 195.145 138.88
608 <O WITH GRAVE> 210 237 237 237 195.146 138.89
609 <O WITH ACUTE> 211 238 238 238 195.147 138.98
610 <O WITH CIRCUMFLEX> 212 235 235 235 195.148 138.99
611 <O WITH TILDE> 213 239 239 239 195.149 138.100
612 <O WITH DIAERESIS> 214 236 236 236 195.150 138.101
613 <MULTIPLICATION SIGN> 215 191 191 191 195.151 138.102
614 <O WITH STROKE> 216 128 128 128 195.152 138.103
615 <U WITH GRAVE> 217 253 253 224 195.153 138.104 ##
616 <U WITH ACUTE> 218 254 254 254 195.154 138.105
617 <U WITH CIRCUMFLEX> 219 251 251 221 195.155 138.106 ##
618 <U WITH DIAERESIS> 220 252 252 252 195.156 138.112
619 <Y WITH ACUTE> 221 173 186 173 195.157 138.113 ** ##
620 <CAPITAL LETTER THORN> 222 174 174 174 195.158 138.114
621 <SMALL LETTER SHARP S> 223 89 89 89 195.159 138.115
622 <a WITH GRAVE> 224 68 68 68 195.160 139.65
623 <a WITH ACUTE> 225 69 69 69 195.161 139.66
624 <a WITH CIRCUMFLEX> 226 66 66 66 195.162 139.67
625 <a WITH TILDE> 227 70 70 70 195.163 139.68
626 <a WITH DIAERESIS> 228 67 67 67 195.164 139.69
627 <a WITH RING ABOVE> 229 71 71 71 195.165 139.70
628 <SMALL LIGATURE ae> 230 156 156 156 195.166 139.71
629 <c WITH CEDILLA> 231 72 72 72 195.167 139.72
630 <e WITH GRAVE> 232 84 84 84 195.168 139.73
631 <e WITH ACUTE> 233 81 81 81 195.169 139.74
632 <e WITH CIRCUMFLEX> 234 82 82 82 195.170 139.81
633 <e WITH DIAERESIS> 235 83 83 83 195.171 139.82
634 <i WITH GRAVE> 236 88 88 88 195.172 139.83
635 <i WITH ACUTE> 237 85 85 85 195.173 139.84
636 <i WITH CIRCUMFLEX> 238 86 86 86 195.174 139.85
637 <i WITH DIAERESIS> 239 87 87 87 195.175 139.86
638 <SMALL LETTER eth> 240 140 140 140 195.176 139.87
639 <n WITH TILDE> 241 73 73 73 195.177 139.88
640 <o WITH GRAVE> 242 205 205 205 195.178 139.89
641 <o WITH ACUTE> 243 206 206 206 195.179 139.98
642 <o WITH CIRCUMFLEX> 244 203 203 203 195.180 139.99
643 <o WITH TILDE> 245 207 207 207 195.181 139.100
644 <o WITH DIAERESIS> 246 204 204 204 195.182 139.101
645 <DIVISION SIGN> 247 225 225 225 195.183 139.102
646 <o WITH STROKE> 248 112 112 112 195.184 139.103
647 <u WITH GRAVE> 249 221 221 192 195.185 139.104 ##
648 <u WITH ACUTE> 250 222 222 222 195.186 139.105
649 <u WITH CIRCUMFLEX> 251 219 219 219 195.187 139.106
650 <u WITH DIAERESIS> 252 220 220 220 195.188 139.112
651 <y WITH ACUTE> 253 141 141 141 195.189 139.113
652 <SMALL LETTER thorn> 254 142 142 142 195.190 139.114
653 <y WITH DIAERESIS> 255 223 223 223 195.191 139.115
654
655 If you would rather see the above table in CCSID 0037 order rather than
656 ASCII + Latin-1 order then run the table through:
657
658 recipe 4
659
660 perl \
661 -ne 'if(/.{29}\d{1,3}\s{2,4}\d{1,3}\s{2,4}\d{1,3}\s{2,4}\d{1,3}/)'\
662 -e '{push(@l,$_)}' \
663 -e 'END{print map{$_->[0]}' \
664 -e ' sort{$a->[1] <=> $b->[1]}' \
665 -e ' map{[$_,substr($_,34,3)]}@l;}' perlebcdic.pod
666
667 If you would rather see it in CCSID 1047 order then change the number
668 34 in the last line to 39, like this:
669
670 recipe 5
671
672 perl \
673 -ne 'if(/.{29}\d{1,3}\s{2,4}\d{1,3}\s{2,4}\d{1,3}\s{2,4}\d{1,3}/)'\
674 -e '{push(@l,$_)}' \
675 -e 'END{print map{$_->[0]}' \
676 -e ' sort{$a->[1] <=> $b->[1]}' \
677 -e ' map{[$_,substr($_,39,3)]}@l;}' perlebcdic.pod
678
679 If you would rather see it in POSIX-BC order then change the number 34
680 in the last line to 44, like this:
681
682 recipe 6
683
684 perl \
685 -ne 'if(/.{29}\d{1,3}\s{2,4}\d{1,3}\s{2,4}\d{1,3}\s{2,4}\d{1,3}/)'\
686 -e '{push(@l,$_)}' \
687 -e 'END{print map{$_->[0]}' \
688 -e ' sort{$a->[1] <=> $b->[1]}' \
689 -e ' map{[$_,substr($_,44,3)]}@l;}' perlebcdic.pod
690
691 Table in hex, sorted in 1047 order
692 Since this document was first written, the convention has become more
693 and more to use hexadecimal notation for code points. To do this with
694 the recipes and to also sort is a multi-step process, so here, for
695 convenience, is the table from above, re-sorted to be in Code Page 1047
696 order, and using hex notation.
697
698 ISO
699 8859-1 POS- CCSID
700 CCSID CCSID CCSID IX- 1047
701 chr 0819 0037 1047 BC UTF-8 UTF-EBCDIC
702 ---------------------------------------------------------------------
703 <NUL> 00 00 00 00 00 00
704 <SOH> 01 01 01 01 01 01
705 <STX> 02 02 02 02 02 02
706 <ETX> 03 03 03 03 03 03
707 <ST> 9C 04 04 04 C2.9C 04
708 <HT> 09 05 05 05 09 05
709 <SSA> 86 06 06 06 C2.86 06
710 <DEL> 7F 07 07 07 7F 07
711 <EPA> 97 08 08 08 C2.97 08
712 <RI> 8D 09 09 09 C2.8D 09
713 <SS2> 8E 0A 0A 0A C2.8E 0A
714 <VT> 0B 0B 0B 0B 0B 0B
715 <FF> 0C 0C 0C 0C 0C 0C
716 <CR> 0D 0D 0D 0D 0D 0D
717 <SO> 0E 0E 0E 0E 0E 0E
718 <SI> 0F 0F 0F 0F 0F 0F
719 <DLE> 10 10 10 10 10 10
720 <DC1> 11 11 11 11 11 11
721 <DC2> 12 12 12 12 12 12
722 <DC3> 13 13 13 13 13 13
723 <OSC> 9D 14 14 14 C2.9D 14
724 <LF> 0A 25 15 15 0A 15 **
725 <BS> 08 16 16 16 08 16
726 <ESA> 87 17 17 17 C2.87 17
727 <CAN> 18 18 18 18 18 18
728 <EOM> 19 19 19 19 19 19
729 <PU2> 92 1A 1A 1A C2.92 1A
730 <SS3> 8F 1B 1B 1B C2.8F 1B
731 <FS> 1C 1C 1C 1C 1C 1C
732 <GS> 1D 1D 1D 1D 1D 1D
733 <RS> 1E 1E 1E 1E 1E 1E
734 <US> 1F 1F 1F 1F 1F 1F
735 <PAD> 80 20 20 20 C2.80 20
736 <HOP> 81 21 21 21 C2.81 21
737 <BPH> 82 22 22 22 C2.82 22
738 <NBH> 83 23 23 23 C2.83 23
739 <IND> 84 24 24 24 C2.84 24
740 <NEL> 85 15 25 25 C2.85 25 **
741 <ETB> 17 26 26 26 17 26
742 <ESC> 1B 27 27 27 1B 27
743 <HTS> 88 28 28 28 C2.88 28
744 <HTJ> 89 29 29 29 C2.89 29
745 <VTS> 8A 2A 2A 2A C2.8A 2A
746 <PLD> 8B 2B 2B 2B C2.8B 2B
747 <PLU> 8C 2C 2C 2C C2.8C 2C
748 <ENQ> 05 2D 2D 2D 05 2D
749 <ACK> 06 2E 2E 2E 06 2E
750 <BEL> 07 2F 2F 2F 07 2F
751 <DCS> 90 30 30 30 C2.90 30
752 <PU1> 91 31 31 31 C2.91 31
753 <SYN> 16 32 32 32 16 32
754 <STS> 93 33 33 33 C2.93 33
755 <CCH> 94 34 34 34 C2.94 34
756 <MW> 95 35 35 35 C2.95 35
757 <SPA> 96 36 36 36 C2.96 36
758 <EOT> 04 37 37 37 04 37
759 <SOS> 98 38 38 38 C2.98 38
760 <SGC> 99 39 39 39 C2.99 39
761 <SCI> 9A 3A 3A 3A C2.9A 3A
762 <CSI> 9B 3B 3B 3B C2.9B 3B
763 <DC4> 14 3C 3C 3C 14 3C
764 <NAK> 15 3D 3D 3D 15 3D
765 <PM> 9E 3E 3E 3E C2.9E 3E
766 <SUB> 1A 3F 3F 3F 1A 3F
767 <SPACE> 20 40 40 40 20 40
768 <NON-BREAKING SPACE> A0 41 41 41 C2.A0 80.41
769 <a WITH CIRCUMFLEX> E2 42 42 42 C3.A2 8B.43
770 <a WITH DIAERESIS> E4 43 43 43 C3.A4 8B.45
771 <a WITH GRAVE> E0 44 44 44 C3.A0 8B.41
772 <a WITH ACUTE> E1 45 45 45 C3.A1 8B.42
773 <a WITH TILDE> E3 46 46 46 C3.A3 8B.44
774 <a WITH RING ABOVE> E5 47 47 47 C3.A5 8B.46
775 <c WITH CEDILLA> E7 48 48 48 C3.A7 8B.48
776 <n WITH TILDE> F1 49 49 49 C3.B1 8B.58
777 <CENT SIGN> A2 4A 4A B0 C2.A2 80.43 ##
778 . 2E 4B 4B 4B 2E 4B
779 < 3C 4C 4C 4C 3C 4C
780 ( 28 4D 4D 4D 28 4D
781 + 2B 4E 4E 4E 2B 4E
782 | 7C 4F 4F 4F 7C 4F
783 & 26 50 50 50 26 50
784 <e WITH ACUTE> E9 51 51 51 C3.A9 8B.4A
785 <e WITH CIRCUMFLEX> EA 52 52 52 C3.AA 8B.51
786 <e WITH DIAERESIS> EB 53 53 53 C3.AB 8B.52
787 <e WITH GRAVE> E8 54 54 54 C3.A8 8B.49
788 <i WITH ACUTE> ED 55 55 55 C3.AD 8B.54
789 <i WITH CIRCUMFLEX> EE 56 56 56 C3.AE 8B.55
790 <i WITH DIAERESIS> EF 57 57 57 C3.AF 8B.56
791 <i WITH GRAVE> EC 58 58 58 C3.AC 8B.53
792 <SMALL LETTER SHARP S> DF 59 59 59 C3.9F 8A.73
793 ! 21 5A 5A 5A 21 5A
794 $ 24 5B 5B 5B 24 5B
795 * 2A 5C 5C 5C 2A 5C
796 ) 29 5D 5D 5D 29 5D
797 ; 3B 5E 5E 5E 3B 5E
798 ^ 5E B0 5F 6A 5E 5F ** ##
799 - 2D 60 60 60 2D 60
800 / 2F 61 61 61 2F 61
801 <A WITH CIRCUMFLEX> C2 62 62 62 C3.82 8A.43
802 <A WITH DIAERESIS> C4 63 63 63 C3.84 8A.45
803 <A WITH GRAVE> C0 64 64 64 C3.80 8A.41
804 <A WITH ACUTE> C1 65 65 65 C3.81 8A.42
805 <A WITH TILDE> C3 66 66 66 C3.83 8A.44
806 <A WITH RING ABOVE> C5 67 67 67 C3.85 8A.46
807 <C WITH CEDILLA> C7 68 68 68 C3.87 8A.48
808 <N WITH TILDE> D1 69 69 69 C3.91 8A.58
809 <BROKEN BAR> A6 6A 6A D0 C2.A6 80.47 ##
810 , 2C 6B 6B 6B 2C 6B
811 % 25 6C 6C 6C 25 6C
812 _ 5F 6D 6D 6D 5F 6D
813 > 3E 6E 6E 6E 3E 6E
814 ? 3F 6F 6F 6F 3F 6F
815 <o WITH STROKE> F8 70 70 70 C3.B8 8B.67
816 <E WITH ACUTE> C9 71 71 71 C3.89 8A.4A
817 <E WITH CIRCUMFLEX> CA 72 72 72 C3.8A 8A.51
818 <E WITH DIAERESIS> CB 73 73 73 C3.8B 8A.52
819 <E WITH GRAVE> C8 74 74 74 C3.88 8A.49
820 <I WITH ACUTE> CD 75 75 75 C3.8D 8A.54
821 <I WITH CIRCUMFLEX> CE 76 76 76 C3.8E 8A.55
822 <I WITH DIAERESIS> CF 77 77 77 C3.8F 8A.56
823 <I WITH GRAVE> CC 78 78 78 C3.8C 8A.53
824 ` 60 79 79 4A 60 79 ##
825 : 3A 7A 7A 7A 3A 7A
826 # 23 7B 7B 7B 23 7B
827 @ 40 7C 7C 7C 40 7C
828 ' 27 7D 7D 7D 27 7D
829 = 3D 7E 7E 7E 3D 7E
830 " 22 7F 7F 7F 22 7F
831 <O WITH STROKE> D8 80 80 80 C3.98 8A.67
832 a 61 81 81 81 61 81
833 b 62 82 82 82 62 82
834 c 63 83 83 83 63 83
835 d 64 84 84 84 64 84
836 e 65 85 85 85 65 85
837 f 66 86 86 86 66 86
838 g 67 87 87 87 67 87
839 h 68 88 88 88 68 88
840 i 69 89 89 89 69 89
841 <LEFT POINTING GUILLEMET> AB 8A 8A 8A C2.AB 80.52
842 <RIGHT POINTING GUILLEMET> BB 8B 8B 8B C2.BB 80.6A
843 <SMALL LETTER eth> F0 8C 8C 8C C3.B0 8B.57
844 <y WITH ACUTE> FD 8D 8D 8D C3.BD 8B.71
845 <SMALL LETTER thorn> FE 8E 8E 8E C3.BE 8B.72
846 <PLUS-OR-MINUS SIGN> B1 8F 8F 8F C2.B1 80.58
847 <DEGREE SIGN> B0 90 90 90 C2.B0 80.57
848 j 6A 91 91 91 6A 91
849 k 6B 92 92 92 6B 92
850 l 6C 93 93 93 6C 93
851 m 6D 94 94 94 6D 94
852 n 6E 95 95 95 6E 95
853 o 6F 96 96 96 6F 96
854 p 70 97 97 97 70 97
855 q 71 98 98 98 71 98
856 r 72 99 99 99 72 99
857 <FEMININE ORDINAL> AA 9A 9A 9A C2.AA 80.51
858 <MASC. ORDINAL INDICATOR> BA 9B 9B 9B C2.BA 80.69
859 <SMALL LIGATURE ae> E6 9C 9C 9C C3.A6 8B.47
860 <CEDILLA> B8 9D 9D 9D C2.B8 80.67
861 <CAPITAL LIGATURE AE> C6 9E 9E 9E C3.86 8A.47
862 <CURRENCY SIGN> A4 9F 9F 9F C2.A4 80.45
863 <MICRO SIGN> B5 A0 A0 A0 C2.B5 80.64
864 ~ 7E A1 A1 FF 7E A1 ##
865 s 73 A2 A2 A2 73 A2
866 t 74 A3 A3 A3 74 A3
867 u 75 A4 A4 A4 75 A4
868 v 76 A5 A5 A5 76 A5
869 w 77 A6 A6 A6 77 A6
870 x 78 A7 A7 A7 78 A7
871 y 79 A8 A8 A8 79 A8
872 z 7A A9 A9 A9 7A A9
873 <INVERTED "!" > A1 AA AA AA C2.A1 80.42
874 <INVERTED QUESTION MARK> BF AB AB AB C2.BF 80.73
875 <CAPITAL LETTER ETH> D0 AC AC AC C3.90 8A.57
876 [ 5B BA AD BB 5B AD ** ##
877 <CAPITAL LETTER THORN> DE AE AE AE C3.9E 8A.72
878 <REGISTERED TRADE MARK> AE AF AF AF C2.AE 80.55
879 <NOT SIGN> AC 5F B0 BA C2.AC 80.53 ** ##
880 <POUND SIGN> A3 B1 B1 B1 C2.A3 80.44
881 <YEN SIGN> A5 B2 B2 B2 C2.A5 80.46
882 <MIDDLE DOT> B7 B3 B3 B3 C2.B7 80.66
883 <COPYRIGHT SIGN> A9 B4 B4 B4 C2.A9 80.4A
884 <SECTION SIGN> A7 B5 B5 B5 C2.A7 80.48
885 <PARAGRAPH SIGN> B6 B6 B6 B6 C2.B6 80.65
886 <FRACTION ONE QUARTER> BC B7 B7 B7 C2.BC 80.70
887 <FRACTION ONE HALF> BD B8 B8 B8 C2.BD 80.71
888 <FRACTION THREE QUARTERS> BE B9 B9 B9 C2.BE 80.72
889 <Y WITH ACUTE> DD AD BA AD C3.9D 8A.71 ** ##
890 <DIAERESIS> A8 BD BB 79 C2.A8 80.49 ** ##
891 <MACRON> AF BC BC A1 C2.AF 80.56 ##
892 ] 5D BB BD BD 5D BD **
893 <ACUTE ACCENT> B4 BE BE BE C2.B4 80.63
894 <MULTIPLICATION SIGN> D7 BF BF BF C3.97 8A.66
895 { 7B C0 C0 FB 7B C0 ##
896 A 41 C1 C1 C1 41 C1
897 B 42 C2 C2 C2 42 C2
898 C 43 C3 C3 C3 43 C3
899 D 44 C4 C4 C4 44 C4
900 E 45 C5 C5 C5 45 C5
901 F 46 C6 C6 C6 46 C6
902 G 47 C7 C7 C7 47 C7
903 H 48 C8 C8 C8 48 C8
904 I 49 C9 C9 C9 49 C9
905 <SOFT HYPHEN> AD CA CA CA C2.AD 80.54
906 <o WITH CIRCUMFLEX> F4 CB CB CB C3.B4 8B.63
907 <o WITH DIAERESIS> F6 CC CC CC C3.B6 8B.65
908 <o WITH GRAVE> F2 CD CD CD C3.B2 8B.59
909 <o WITH ACUTE> F3 CE CE CE C3.B3 8B.62
910 <o WITH TILDE> F5 CF CF CF C3.B5 8B.64
911 } 7D D0 D0 FD 7D D0 ##
912 J 4A D1 D1 D1 4A D1
913 K 4B D2 D2 D2 4B D2
914 L 4C D3 D3 D3 4C D3
915 M 4D D4 D4 D4 4D D4
916 N 4E D5 D5 D5 4E D5
917 O 4F D6 D6 D6 4F D6
918 P 50 D7 D7 D7 50 D7
919 Q 51 D8 D8 D8 51 D8
920 R 52 D9 D9 D9 52 D9
921 <SUPERSCRIPT ONE> B9 DA DA DA C2.B9 80.68
922 <u WITH CIRCUMFLEX> FB DB DB DB C3.BB 8B.6A
923 <u WITH DIAERESIS> FC DC DC DC C3.BC 8B.70
924 <u WITH GRAVE> F9 DD DD C0 C3.B9 8B.68 ##
925 <u WITH ACUTE> FA DE DE DE C3.BA 8B.69
926 <y WITH DIAERESIS> FF DF DF DF C3.BF 8B.73
927 \ 5C E0 E0 BC 5C E0 ##
928 <DIVISION SIGN> F7 E1 E1 E1 C3.B7 8B.66
929 S 53 E2 E2 E2 53 E2
930 T 54 E3 E3 E3 54 E3
931 U 55 E4 E4 E4 55 E4
932 V 56 E5 E5 E5 56 E5
933 W 57 E6 E6 E6 57 E6
934 X 58 E7 E7 E7 58 E7
935 Y 59 E8 E8 E8 59 E8
936 Z 5A E9 E9 E9 5A E9
937 <SUPERSCRIPT TWO> B2 EA EA EA C2.B2 80.59
938 <O WITH CIRCUMFLEX> D4 EB EB EB C3.94 8A.63
939 <O WITH DIAERESIS> D6 EC EC EC C3.96 8A.65
940 <O WITH GRAVE> D2 ED ED ED C3.92 8A.59
941 <O WITH ACUTE> D3 EE EE EE C3.93 8A.62
942 <O WITH TILDE> D5 EF EF EF C3.95 8A.64
943 0 30 F0 F0 F0 30 F0
944 1 31 F1 F1 F1 31 F1
945 2 32 F2 F2 F2 32 F2
946 3 33 F3 F3 F3 33 F3
947 4 34 F4 F4 F4 34 F4
948 5 35 F5 F5 F5 35 F5
949 6 36 F6 F6 F6 36 F6
950 7 37 F7 F7 F7 37 F7
951 8 38 F8 F8 F8 38 F8
952 9 39 F9 F9 F9 39 F9
953 <SUPERSCRIPT THREE> B3 FA FA FA C2.B3 80.62
954 <U WITH CIRCUMFLEX> DB FB FB DD C3.9B 8A.6A ##
955 <U WITH DIAERESIS> DC FC FC FC C3.9C 8A.70
956 <U WITH GRAVE> D9 FD FD E0 C3.99 8A.68 ##
957 <U WITH ACUTE> DA FE FE FE C3.9A 8A.69
958 <APC> 9F FF FF 5F C2.9F FF ##
959
961 It is possible to determine which character set you are operating
962 under. But first you need to be really really sure you need to do
963 this. Your code will be simpler and probably just as portable if you
964 don't have to test the character set and do different things,
965 depending. There are actually only very few circumstances where it's
966 not easy to write straight-line code portable to all character sets.
967 See "Unicode and EBCDIC" in perluniintro for how to portably specify
968 characters.
969
970 But there are some cases where you may want to know which character set
971 you are running under. One possible example is doing sorting in inner
972 loops where performance is critical.
973
974 To determine if you are running under ASCII or EBCDIC, you can use the
975 return value of "ord()" or "chr()" to test one or more character
976 values. For example:
977
978 $is_ascii = "A" eq chr(65);
979 $is_ebcdic = "A" eq chr(193);
980 $is_ascii = ord("A") == 65;
981 $is_ebcdic = ord("A") == 193;
982
983 There's even less need to distinguish between EBCDIC code pages, but to
984 do so try looking at one or more of the characters that differ between
985 them.
986
987 $is_ascii = ord('[') == 91;
988 $is_ebcdic_37 = ord('[') == 186;
989 $is_ebcdic_1047 = ord('[') == 173;
990 $is_ebcdic_POSIX_BC = ord('[') == 187;
991
992 However, it would be unwise to write tests such as:
993
994 $is_ascii = "\r" ne chr(13); # WRONG
995 $is_ascii = "\n" ne chr(10); # ILL ADVISED
996
997 Obviously the first of these will fail to distinguish most ASCII
998 platforms from either a CCSID 0037, a 1047, or a POSIX-BC EBCDIC
999 platform since ""\r" eq chr(13)" under all of those coded character
1000 sets. But note too that because "\n" is "chr(13)" and "\r" is
1001 "chr(10)" on old Macintosh (which is an ASCII platform) the second
1002 $is_ascii test will lead to trouble there.
1003
1004 To determine whether or not perl was built under an EBCDIC code page
1005 you can use the Config module like so:
1006
1007 use Config;
1008 $is_ebcdic = $Config{'ebcdic'} eq 'define';
1009
1011 "utf8::unicode_to_native()" and "utf8::native_to_unicode()"
1012 These functions take an input numeric code point in one encoding and
1013 return what its equivalent value is in the other.
1014
1015 See utf8.
1016
1017 tr///
1018 In order to convert a string of characters from one character set to
1019 another a simple list of numbers, such as in the right columns in the
1020 above table, along with Perl's "tr///" operator is all that is needed.
1021 The data in the table are in ASCII/Latin1 order, hence the EBCDIC
1022 columns provide easy-to-use ASCII/Latin1 to EBCDIC operations that are
1023 also easily reversed.
1024
1025 For example, to convert ASCII/Latin1 to code page 037 take the output
1026 of the second numbers column from the output of recipe 2 (modified to
1027 add "\" characters), and use it in "tr///" like so:
1028
1029 $cp_037 =
1030 '\x00\x01\x02\x03\x37\x2D\x2E\x2F\x16\x05\x25\x0B\x0C\x0D\x0E\x0F' .
1031 '\x10\x11\x12\x13\x3C\x3D\x32\x26\x18\x19\x3F\x27\x1C\x1D\x1E\x1F' .
1032 '\x40\x5A\x7F\x7B\x5B\x6C\x50\x7D\x4D\x5D\x5C\x4E\x6B\x60\x4B\x61' .
1033 '\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\x7A\x5E\x4C\x7E\x6E\x6F' .
1034 '\x7C\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xD1\xD2\xD3\xD4\xD5\xD6' .
1035 '\xD7\xD8\xD9\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xBA\xE0\xBB\xB0\x6D' .
1036 '\x79\x81\x82\x83\x84\x85\x86\x87\x88\x89\x91\x92\x93\x94\x95\x96' .
1037 '\x97\x98\x99\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xC0\x4F\xD0\xA1\x07' .
1038 '\x20\x21\x22\x23\x24\x15\x06\x17\x28\x29\x2A\x2B\x2C\x09\x0A\x1B' .
1039 '\x30\x31\x1A\x33\x34\x35\x36\x08\x38\x39\x3A\x3B\x04\x14\x3E\xFF' .
1040 '\x41\xAA\x4A\xB1\x9F\xB2\x6A\xB5\xBD\xB4\x9A\x8A\x5F\xCA\xAF\xBC' .
1041 '\x90\x8F\xEA\xFA\xBE\xA0\xB6\xB3\x9D\xDA\x9B\x8B\xB7\xB8\xB9\xAB' .
1042 '\x64\x65\x62\x66\x63\x67\x9E\x68\x74\x71\x72\x73\x78\x75\x76\x77' .
1043 '\xAC\x69\xED\xEE\xEB\xEF\xEC\xBF\x80\xFD\xFE\xFB\xFC\xAD\xAE\x59' .
1044 '\x44\x45\x42\x46\x43\x47\x9C\x48\x54\x51\x52\x53\x58\x55\x56\x57' .
1045 '\x8C\x49\xCD\xCE\xCB\xCF\xCC\xE1\x70\xDD\xDE\xDB\xDC\x8D\x8E\xDF';
1046
1047 my $ebcdic_string = $ascii_string;
1048 eval '$ebcdic_string =~ tr/\000-\377/' . $cp_037 . '/';
1049
1050 To convert from EBCDIC 037 to ASCII just reverse the order of the tr///
1051 arguments like so:
1052
1053 my $ascii_string = $ebcdic_string;
1054 eval '$ascii_string =~ tr/' . $cp_037 . '/\000-\377/';
1055
1056 Similarly one could take the output of the third numbers column from
1057 recipe 2 to obtain a $cp_1047 table. The fourth numbers column of the
1058 output from recipe 2 could provide a $cp_posix_bc table suitable for
1059 transcoding as well.
1060
1061 If you wanted to see the inverse tables, you would first have to sort
1062 on the desired numbers column as in recipes 4, 5 or 6, then take the
1063 output of the first numbers column.
1064
1065 iconv
1066 XPG operability often implies the presence of an iconv utility
1067 available from the shell or from the C library. Consult your system's
1068 documentation for information on iconv.
1069
1070 On OS/390 or z/OS see the iconv(1) manpage. One way to invoke the
1071 "iconv" shell utility from within perl would be to:
1072
1073 # OS/390 or z/OS example
1074 $ascii_data = `echo '$ebcdic_data'| iconv -f IBM-1047 -t ISO8859-1`
1075
1076 or the inverse map:
1077
1078 # OS/390 or z/OS example
1079 $ebcdic_data = `echo '$ascii_data'| iconv -f ISO8859-1 -t IBM-1047`
1080
1081 For other Perl-based conversion options see the "Convert::*" modules on
1082 CPAN.
1083
1084 C RTL
1085 The OS/390 and z/OS C run-time libraries provide "_atoe()" and
1086 "_etoa()" functions.
1087
1089 The ".." range operator treats certain character ranges with care on
1090 EBCDIC platforms. For example the following array will have twenty six
1091 elements on either an EBCDIC platform or an ASCII platform:
1092
1093 @alphabet = ('A'..'Z'); # $#alphabet == 25
1094
1095 The bitwise operators such as & ^ | may return different results when
1096 operating on string or character data in a Perl program running on an
1097 EBCDIC platform than when run on an ASCII platform. Here is an example
1098 adapted from the one in perlop:
1099
1100 # EBCDIC-based examples
1101 print "j p \n" ^ " a h"; # prints "JAPH\n"
1102 print "JA" | " ph\n"; # prints "japh\n"
1103 print "JAPH\nJunk" & "\277\277\277\277\277"; # prints "japh\n";
1104 print 'p N$' ^ " E<H\n"; # prints "Perl\n";
1105
1106 An interesting property of the 32 C0 control characters in the ASCII
1107 table is that they can "literally" be constructed as control characters
1108 in Perl, e.g. "(chr(0)" eq "\c@")> "(chr(1)" eq "\cA")>, and so on.
1109 Perl on EBCDIC platforms has been ported to take "\c@" to chr(0) and
1110 "\cA" to chr(1), etc. as well, but the characters that result depend on
1111 which code page you are using. The table below uses the standard
1112 acronyms for the controls. The POSIX-BC and 1047 sets are identical
1113 throughout this range and differ from the 0037 set at only one spot (21
1114 decimal). Note that the line terminator character may be generated by
1115 "\cJ" on ASCII platforms but by "\cU" on 1047 or POSIX-BC platforms and
1116 cannot be generated as a "\c.letter." control character on 0037
1117 platforms. Note also that "\c\" cannot be the final element in a
1118 string or regex, as it will absorb the terminator. But "\c\X" is a
1119 "FILE SEPARATOR" concatenated with X for all X. The outlier "\c?" on
1120 ASCII, which yields a non-C0 control "DEL", yields the outlier control
1121 "APC" on EBCDIC, the one that isn't in the block of contiguous
1122 controls. Note that a subtlety of this is that "\c?" on ASCII
1123 platforms is an ASCII character, while it isn't equivalent to any ASCII
1124 character in EBCDIC platforms.
1125
1126 chr ord 8859-1 0037 1047 && POSIX-BC
1127 -----------------------------------------------------------------------
1128 \c@ 0 <NUL> <NUL> <NUL>
1129 \cA 1 <SOH> <SOH> <SOH>
1130 \cB 2 <STX> <STX> <STX>
1131 \cC 3 <ETX> <ETX> <ETX>
1132 \cD 4 <EOT> <ST> <ST>
1133 \cE 5 <ENQ> <HT> <HT>
1134 \cF 6 <ACK> <SSA> <SSA>
1135 \cG 7 <BEL> <DEL> <DEL>
1136 \cH 8 <BS> <EPA> <EPA>
1137 \cI 9 <HT> <RI> <RI>
1138 \cJ 10 <LF> <SS2> <SS2>
1139 \cK 11 <VT> <VT> <VT>
1140 \cL 12 <FF> <FF> <FF>
1141 \cM 13 <CR> <CR> <CR>
1142 \cN 14 <SO> <SO> <SO>
1143 \cO 15 <SI> <SI> <SI>
1144 \cP 16 <DLE> <DLE> <DLE>
1145 \cQ 17 <DC1> <DC1> <DC1>
1146 \cR 18 <DC2> <DC2> <DC2>
1147 \cS 19 <DC3> <DC3> <DC3>
1148 \cT 20 <DC4> <OSC> <OSC>
1149 \cU 21 <NAK> <NEL> <LF> **
1150 \cV 22 <SYN> <BS> <BS>
1151 \cW 23 <ETB> <ESA> <ESA>
1152 \cX 24 <CAN> <CAN> <CAN>
1153 \cY 25 <EOM> <EOM> <EOM>
1154 \cZ 26 <SUB> <PU2> <PU2>
1155 \c[ 27 <ESC> <SS3> <SS3>
1156 \c\X 28 <FS>X <FS>X <FS>X
1157 \c] 29 <GS> <GS> <GS>
1158 \c^ 30 <RS> <RS> <RS>
1159 \c_ 31 <US> <US> <US>
1160 \c? * <DEL> <APC> <APC>
1161
1162 "*" Note: "\c?" maps to ordinal 127 ("DEL") on ASCII platforms, but
1163 since ordinal 127 is a not a control character on EBCDIC machines,
1164 "\c?" instead maps on them to "APC", which is 255 in 0037 and 1047, and
1165 95 in POSIX-BC.
1166
1168 "chr()" "chr()" must be given an EBCDIC code number argument to yield a
1169 desired character return value on an EBCDIC platform. For
1170 example:
1171
1172 $CAPITAL_LETTER_A = chr(193);
1173
1174 "ord()" "ord()" will return EBCDIC code number values on an EBCDIC
1175 platform. For example:
1176
1177 $the_number_193 = ord("A");
1178
1179 "pack()"
1180 The "c" and "C" templates for "pack()" are dependent upon
1181 character set encoding. Examples of usage on EBCDIC include:
1182
1183 $foo = pack("CCCC",193,194,195,196);
1184 # $foo eq "ABCD"
1185 $foo = pack("C4",193,194,195,196);
1186 # same thing
1187
1188 $foo = pack("ccxxcc",193,194,195,196);
1189 # $foo eq "AB\0\0CD"
1190
1191 The "U" template has been ported to mean "Unicode" on all
1192 platforms so that
1193
1194 pack("U", 65) eq 'A'
1195
1196 is true on all platforms. If you want native code points for
1197 the low 256, use the "W" template. This means that the
1198 equivalences
1199
1200 pack("W", ord($character)) eq $character
1201 unpack("W", $character) == ord $character
1202
1203 will hold.
1204
1205 "print()"
1206 One must be careful with scalars and strings that are passed to
1207 print that contain ASCII encodings. One common place for this
1208 to occur is in the output of the MIME type header for CGI
1209 script writing. For example, many Perl programming guides
1210 recommend something similar to:
1211
1212 print "Content-type:\ttext/html\015\012\015\012";
1213 # this may be wrong on EBCDIC
1214
1215 You can instead write
1216
1217 print "Content-type:\ttext/html\r\n\r\n"; # OK for DGW et al
1218
1219 and have it work portably.
1220
1221 That is because the translation from EBCDIC to ASCII is done by
1222 the web server in this case. Consult your web server's
1223 documentation for further details.
1224
1225 "printf()"
1226 The formats that can convert characters to numbers and vice
1227 versa will be different from their ASCII counterparts when
1228 executed on an EBCDIC platform. Examples include:
1229
1230 printf("%c%c%c",193,194,195); # prints ABC
1231
1232 "sort()"
1233 EBCDIC sort results may differ from ASCII sort results
1234 especially for mixed case strings. This is discussed in more
1235 detail below.
1236
1237 "sprintf()"
1238 See the discussion of "printf()" above. An example of the use
1239 of sprintf would be:
1240
1241 $CAPITAL_LETTER_A = sprintf("%c",193);
1242
1243 "unpack()"
1244 See the discussion of "pack()" above.
1245
1246 Note that it is possible to write portable code for these by specifying
1247 things in Unicode numbers, and using a conversion function:
1248
1249 printf("%c",utf8::unicode_to_native(65)); # prints A on all
1250 # platforms
1251 print utf8::native_to_unicode(ord("A")); # Likewise, prints 65
1252
1253 See "Unicode and EBCDIC" in perluniintro and "CONVERSIONS" for other
1254 options.
1255
1257 You can write your regular expressions just like someone on an ASCII
1258 platform would do. But keep in mind that using octal or hex notation
1259 to specify a particular code point will give you the character that the
1260 EBCDIC code page natively maps to it. (This is also true of all
1261 double-quoted strings.) If you want to write portably, just use the
1262 "\N{U+...}" notation everywhere where you would have used "\x{...}",
1263 and don't use octal notation at all.
1264
1265 Starting in Perl v5.22, this applies to ranges in bracketed character
1266 classes. If you say, for example, "qr/[\N{U+20}-\N{U+7F}]/", it means
1267 the characters "\N{U+20}", "\N{U+21}", ..., "\N{U+7F}". This range is
1268 all the printable characters that the ASCII character set contains.
1269
1270 Prior to v5.22, you couldn't specify any ranges portably, except
1271 (starting in Perl v5.5.3) all subsets of the "[A-Z]" and "[a-z]" ranges
1272 are specially coded to not pick up gap characters. For example,
1273 characters such as "o" ("o WITH CIRCUMFLEX") that lie between "I" and
1274 "J" would not be matched by the regular expression range "/[H-K]/".
1275 But if either of the range end points is explicitly numeric (and
1276 neither is specified by "\N{U+...}"), the gap characters are matched:
1277
1278 /[\x89-\x91]/
1279
1280 will match "\x8e", even though "\x89" is "i" and "\x91 " is "j", and
1281 "\x8e" is a gap character, from the alphabetic viewpoint.
1282
1283 Another construct to be wary of is the inappropriate use of hex (unless
1284 you use "\N{U+...}") or octal constants in regular expressions.
1285 Consider the following set of subs:
1286
1287 sub is_c0 {
1288 my $char = substr(shift,0,1);
1289 $char =~ /[\000-\037]/;
1290 }
1291
1292 sub is_print_ascii {
1293 my $char = substr(shift,0,1);
1294 $char =~ /[\040-\176]/;
1295 }
1296
1297 sub is_delete {
1298 my $char = substr(shift,0,1);
1299 $char eq "\177";
1300 }
1301
1302 sub is_c1 {
1303 my $char = substr(shift,0,1);
1304 $char =~ /[\200-\237]/;
1305 }
1306
1307 sub is_latin_1 { # But not ASCII; not C1
1308 my $char = substr(shift,0,1);
1309 $char =~ /[\240-\377]/;
1310 }
1311
1312 These are valid only on ASCII platforms. Starting in Perl v5.22,
1313 simply changing the octal constants to equivalent "\N{U+...}" values
1314 makes them portable:
1315
1316 sub is_c0 {
1317 my $char = substr(shift,0,1);
1318 $char =~ /[\N{U+00}-\N{U+1F}]/;
1319 }
1320
1321 sub is_print_ascii {
1322 my $char = substr(shift,0,1);
1323 $char =~ /[\N{U+20}-\N{U+7E}]/;
1324 }
1325
1326 sub is_delete {
1327 my $char = substr(shift,0,1);
1328 $char eq "\N{U+7F}";
1329 }
1330
1331 sub is_c1 {
1332 my $char = substr(shift,0,1);
1333 $char =~ /[\N{U+80}-\N{U+9F}]/;
1334 }
1335
1336 sub is_latin_1 { # But not ASCII; not C1
1337 my $char = substr(shift,0,1);
1338 $char =~ /[\N{U+A0}-\N{U+FF}]/;
1339 }
1340
1341 And here are some alternative portable ways to write them:
1342
1343 sub Is_c0 {
1344 my $char = substr(shift,0,1);
1345 return $char =~ /[[:cntrl:]]/a && ! Is_delete($char);
1346
1347 # Alternatively:
1348 # return $char =~ /[[:cntrl:]]/
1349 # && $char =~ /[[:ascii:]]/
1350 # && ! Is_delete($char);
1351 }
1352
1353 sub Is_print_ascii {
1354 my $char = substr(shift,0,1);
1355
1356 return $char =~ /[[:print:]]/a;
1357
1358 # Alternatively:
1359 # return $char =~ /[[:print:]]/ && $char =~ /[[:ascii:]]/;
1360
1361 # Or
1362 # return $char
1363 # =~ /[ !"\#\$%&'()*+,\-.\/0-9:;<=>?\@A-Z[\\\]^_`a-z{|}~]/;
1364 }
1365
1366 sub Is_delete {
1367 my $char = substr(shift,0,1);
1368 return utf8::native_to_unicode(ord $char) == 0x7F;
1369 }
1370
1371 sub Is_c1 {
1372 use feature 'unicode_strings';
1373 my $char = substr(shift,0,1);
1374 return $char =~ /[[:cntrl:]]/ && $char !~ /[[:ascii:]]/;
1375 }
1376
1377 sub Is_latin_1 { # But not ASCII; not C1
1378 use feature 'unicode_strings';
1379 my $char = substr(shift,0,1);
1380 return ord($char) < 256
1381 && $char !~ /[[:ascii:]]/
1382 && $char !~ /[[:cntrl:]]/;
1383 }
1384
1385 Another way to write "Is_latin_1()" would be to use the characters in
1386 the range explicitly:
1387
1388 sub Is_latin_1 {
1389 my $char = substr(shift,0,1);
1390 $char =~ /[ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXAAAA~AeAaAECEEEEeIIIIe]
1391 [D‐N~OOOO~OeXOUUUUeYLPssaaaa~aeaaaeceeeeeiiiied`n~oooo~oeXouuuueybpye]/x;
1392 }
1393
1394 Although that form may run into trouble in network transit (due to the
1395 presence of 8 bit characters) or on non ISO-Latin character sets. But
1396 it does allow "Is_c1" to be rewritten so it works on Perls that don't
1397 have 'unicode_strings' (earlier than v5.14):
1398
1399 sub Is_latin_1 { # But not ASCII; not C1
1400 my $char = substr(shift,0,1);
1401 return ord($char) < 256
1402 && $char !~ /[[:ascii:]]/
1403 && ! Is_latin1($char);
1404 }
1405
1407 Most socket programming assumes ASCII character encodings in network
1408 byte order. Exceptions can include CGI script writing under a host web
1409 server where the server may take care of translation for you. Most
1410 host web servers convert EBCDIC data to ISO-8859-1 or Unicode on
1411 output.
1412
1414 One big difference between ASCII-based character sets and EBCDIC ones
1415 are the relative positions of the characters when sorted in native
1416 order. Of most concern are the upper- and lowercase letters, the
1417 digits, and the underscore ("_"). On ASCII platforms the native sort
1418 order has the digits come before the uppercase letters which come
1419 before the underscore which comes before the lowercase letters. On
1420 EBCDIC, the underscore comes first, then the lowercase letters, then
1421 the uppercase ones, and the digits last. If sorted on an ASCII-based
1422 platform, the two-letter abbreviation for a physician comes before the
1423 two letter abbreviation for drive; that is:
1424
1425 @sorted = sort(qw(Dr. dr.)); # @sorted holds ('Dr.','dr.') on ASCII,
1426 # but ('dr.','Dr.') on EBCDIC
1427
1428 The property of lowercase before uppercase letters in EBCDIC is even
1429 carried to the Latin 1 EBCDIC pages such as 0037 and 1047. An example
1430 would be that "Ee" ("E WITH DIAERESIS", 203) comes before "ee" ("e WITH
1431 DIAERESIS", 235) on an ASCII platform, but the latter (83) comes before
1432 the former (115) on an EBCDIC platform. (Astute readers will note that
1433 the uppercase version of "ss" "SMALL LETTER SHARP S" is simply "SS" and
1434 that the upper case versions of "ye" (small "y WITH DIAERESIS") and "X"
1435 ("MICRO SIGN") are not in the 0..255 range but are in Unicode, in a
1436 Unicode enabled Perl).
1437
1438 The sort order will cause differences between results obtained on ASCII
1439 platforms versus EBCDIC platforms. What follows are some suggestions
1440 on how to deal with these differences.
1441
1442 Ignore ASCII vs. EBCDIC sort differences.
1443 This is the least computationally expensive strategy. It may require
1444 some user education.
1445
1446 Use a sort helper function
1447 This is completely general, but the most computationally expensive
1448 strategy. Choose one or the other character set and transform to that
1449 for every sort comparison. Here's a complete example that transforms
1450 to ASCII sort order:
1451
1452 sub native_to_uni($) {
1453 my $string = shift;
1454
1455 # Saves time on an ASCII platform
1456 return $string if ord 'A' == 65;
1457
1458 my $output = "";
1459 for my $i (0 .. length($string) - 1) {
1460 $output
1461 .= chr(utf8::native_to_unicode(ord(substr($string, $i, 1))));
1462 }
1463
1464 # Preserve utf8ness of input onto the output, even if it didn't need
1465 # to be utf8
1466 utf8::upgrade($output) if utf8::is_utf8($string);
1467
1468 return $output;
1469 }
1470
1471 sub ascii_order { # Sort helper
1472 return native_to_uni($a) cmp native_to_uni($b);
1473 }
1474
1475 sort ascii_order @list;
1476
1477 MONO CASE then sort data (for non-digits, non-underscore)
1478 If you don't care about where digits and underscore sort to, you can do
1479 something like this
1480
1481 sub case_insensitive_order { # Sort helper
1482 return lc($a) cmp lc($b)
1483 }
1484
1485 sort case_insensitive_order @list;
1486
1487 If performance is an issue, and you don't care if the output is in the
1488 same case as the input, Use "tr///" to transform to the case most
1489 employed within the data. If the data are primarily UPPERCASE
1490 non-Latin1, then apply "tr/[a-z]/[A-Z]/", and then "sort()". If the
1491 data are primarily lowercase non Latin1 then apply "tr/[A-Z]/[a-z]/"
1492 before sorting. If the data are primarily UPPERCASE and include
1493 Latin-1 characters then apply:
1494
1495 tr/[a-z]/[A-Z]/;
1496 tr/[aaaa~aeaaaeceeeeeiiiied`n~oooo~oeouuuueybp]/[AAAA~AeAaAECEEEEeIIIIeD‐N~OOOO~OeOUUUUeYLP/;
1497 s/ss/SS/g;
1498
1499 then "sort()". If you have a choice, it's better to lowercase things
1500 to avoid the problems of the two Latin-1 characters whose uppercase is
1501 outside Latin-1: "ye" (small "y WITH DIAERESIS") and "X" ("MICRO
1502 SIGN"). If you do need to upppercase, you can; with a Unicode-enabled
1503 Perl, do:
1504
1505 tr/ye/\x{178}/;
1506 tr/X/\x{39C}/;
1507
1508 Perform sorting on one type of platform only.
1509 This strategy can employ a network connection. As such it would be
1510 computationally expensive.
1511
1513 There are a variety of ways of transforming data with an intra
1514 character set mapping that serve a variety of purposes. Sorting was
1515 discussed in the previous section and a few of the other more popular
1516 mapping techniques are discussed next.
1517
1518 URL decoding and encoding
1519 Note that some URLs have hexadecimal ASCII code points in them in an
1520 attempt to overcome character or protocol limitation issues. For
1521 example the tilde character is not on every keyboard hence a URL of the
1522 form:
1523
1524 http://www.pvhp.com/~pvhp/
1525
1526 may also be expressed as either of:
1527
1528 http://www.pvhp.com/%7Epvhp/
1529
1530 http://www.pvhp.com/%7epvhp/
1531
1532 where 7E is the hexadecimal ASCII code point for "~". Here is an
1533 example of decoding such a URL in any EBCDIC code page:
1534
1535 $url = 'http://www.pvhp.com/%7Epvhp/';
1536 $url =~ s/%([0-9a-fA-F]{2})/
1537 pack("c",utf8::unicode_to_native(hex($1)))/xge;
1538
1539 Conversely, here is a partial solution for the task of encoding such a
1540 URL in any EBCDIC code page:
1541
1542 $url = 'http://www.pvhp.com/~pvhp/';
1543 # The following regular expression does not address the
1544 # mappings for: ('.' => '%2E', '/' => '%2F', ':' => '%3A')
1545 $url =~ s/([\t "#%&\(\),;<=>\?\@\[\\\]^`{|}~])/
1546 sprintf("%%%02X",utf8::native_to_unicode(ord($1)))/xge;
1547
1548 where a more complete solution would split the URL into components and
1549 apply a full s/// substitution only to the appropriate parts.
1550
1551 uu encoding and decoding
1552 The "u" template to "pack()" or "unpack()" will render EBCDIC data in
1553 EBCDIC characters equivalent to their ASCII counterparts. For example,
1554 the following will print "Yes indeed\n" on either an ASCII or EBCDIC
1555 computer:
1556
1557 $all_byte_chrs = '';
1558 for (0..255) { $all_byte_chrs .= chr($_); }
1559 $uuencode_byte_chrs = pack('u', $all_byte_chrs);
1560 ($uu = <<'ENDOFHEREDOC') =~ s/^\s*//gm;
1561 M``$"`P0%!@<("0H+#`T.#Q`1$A,4%187&!D:&QP='A\@(2(C)"4F)R@I*BLL
1562 M+2XO,#$R,S0U-C<X.3H[/#T^/T!!0D-$149'2$E*2TQ-3D]045)35%565UA9
1563 M6EM<75Y?8&%B8V1E9F=H:6IK;&UN;W!Q<G-T=79W>'EZ>WQ]?G^`@8*#A(6&
1564 MAXB)BHN,C8Z/D)&2DY25EI>8F9J;G)V>GZ"AHJ.DI::GJ*FJJZRMKJ^PL;*S
1565 MM+6VM[BYNKN\O;Z_P,'"P\3%QL?(R<K+S,W.S]#1TM/4U=;7V-G:V]S=WM_@
1566 ?X>+CY.7FY^CIZNOL[>[O\/'R\_3U]O?X^?K[_/W^_P``
1567 ENDOFHEREDOC
1568 if ($uuencode_byte_chrs eq $uu) {
1569 print "Yes ";
1570 }
1571 $uudecode_byte_chrs = unpack('u', $uuencode_byte_chrs);
1572 if ($uudecode_byte_chrs eq $all_byte_chrs) {
1573 print "indeed\n";
1574 }
1575
1576 Here is a very spartan uudecoder that will work on EBCDIC:
1577
1578 #!/usr/local/bin/perl
1579 $_ = <> until ($mode,$file) = /^begin\s*(\d*)\s*(\S*)/;
1580 open(OUT, "> $file") if $file ne "";
1581 while(<>) {
1582 last if /^end/;
1583 next if /[a-z]/;
1584 next unless int((((utf8::native_to_unicode(ord()) - 32 ) & 077)
1585 + 2) / 3)
1586 == int(length() / 4);
1587 print OUT unpack("u", $_);
1588 }
1589 close(OUT);
1590 chmod oct($mode), $file;
1591
1592 Quoted-Printable encoding and decoding
1593 On ASCII-encoded platforms it is possible to strip characters outside
1594 of the printable set using:
1595
1596 # This QP encoder works on ASCII only
1597 $qp_string =~ s/([=\x00-\x1F\x80-\xFF])/
1598 sprintf("=%02X",ord($1))/xge;
1599
1600 Starting in Perl v5.22, this is trivially changeable to work portably
1601 on both ASCII and EBCDIC platforms.
1602
1603 # This QP encoder works on both ASCII and EBCDIC
1604 $qp_string =~ s/([=\N{U+00}-\N{U+1F}\N{U+80}-\N{U+FF}])/
1605 sprintf("=%02X",ord($1))/xge;
1606
1607 For earlier Perls, a QP encoder that works on both ASCII and EBCDIC
1608 platforms would look somewhat like the following:
1609
1610 $delete = utf8::unicode_to_native(ord("\x7F"));
1611 $qp_string =~
1612 s/([^[:print:]$delete])/
1613 sprintf("=%02X",utf8::native_to_unicode(ord($1)))/xage;
1614
1615 (although in production code the substitutions might be done in the
1616 EBCDIC branch with the function call and separately in the ASCII branch
1617 without the expense of the identity map; in Perl v5.22, the identity
1618 map is optimized out so there is no expense, but the alternative above
1619 is simpler and is also available in v5.22).
1620
1621 Such QP strings can be decoded with:
1622
1623 # This QP decoder is limited to ASCII only
1624 $string =~ s/=([[:xdigit:][[:xdigit:])/chr hex $1/ge;
1625 $string =~ s/=[\n\r]+$//;
1626
1627 Whereas a QP decoder that works on both ASCII and EBCDIC platforms
1628 would look somewhat like the following:
1629
1630 $string =~ s/=([[:xdigit:][:xdigit:]])/
1631 chr utf8::native_to_unicode(hex $1)/xge;
1632 $string =~ s/=[\n\r]+$//;
1633
1634 Caesarean ciphers
1635 The practice of shifting an alphabet one or more characters for
1636 encipherment dates back thousands of years and was explicitly detailed
1637 by Gaius Julius Caesar in his Gallic Wars text. A single alphabet
1638 shift is sometimes referred to as a rotation and the shift amount is
1639 given as a number $n after the string 'rot' or "rot$n". Rot0 and rot26
1640 would designate identity maps on the 26-letter English version of the
1641 Latin alphabet. Rot13 has the interesting property that alternate
1642 subsequent invocations are identity maps (thus rot13 is its own non-
1643 trivial inverse in the group of 26 alphabet rotations). Hence the
1644 following is a rot13 encoder and decoder that will work on ASCII and
1645 EBCDIC platforms:
1646
1647 #!/usr/local/bin/perl
1648
1649 while(<>){
1650 tr/n-za-mN-ZA-M/a-zA-Z/;
1651 print;
1652 }
1653
1654 In one-liner form:
1655
1656 perl -ne 'tr/n-za-mN-ZA-M/a-zA-Z/;print'
1657
1659 Perl deliberately randomizes hash order for security purposes on both
1660 ASCII and EBCDIC platforms.
1661
1662 EBCDIC checksums will differ for the same file translated into ASCII
1663 and vice versa.
1664
1666 Internationalization (I18N) and localization (L10N) are supported at
1667 least in principle even on EBCDIC platforms. The details are system-
1668 dependent and discussed under the "OS ISSUES" section below.
1669
1671 Perl works with UTF-EBCDIC, a multi-byte encoding. In Perls earlier
1672 than v5.22, there may be various bugs in this regard.
1673
1674 Legacy multi byte EBCDIC code pages XXX.
1675
1677 There may be a few system-dependent issues of concern to EBCDIC Perl
1678 programmers.
1679
1680 OS/400
1681 PASE The PASE environment is a runtime environment for OS/400 that
1682 can run executables built for PowerPC AIX in OS/400; see
1683 perlos400. PASE is ASCII-based, not EBCDIC-based as the ILE.
1684
1685 IFS access
1686 XXX.
1687
1688 OS/390, z/OS
1689 Perl runs under Unix Systems Services or USS.
1690
1691 "sigaction"
1692 "SA_SIGINFO" can have segmentation faults.
1693
1694 "chcp" chcp is supported as a shell utility for displaying and
1695 changing one's code page. See also chcp(1).
1696
1697 dataset access
1698 For sequential data set access try:
1699
1700 my @ds_records = `cat //DSNAME`;
1701
1702 or:
1703
1704 my @ds_records = `cat //'HLQ.DSNAME'`;
1705
1706 See also the OS390::Stdio module on CPAN.
1707
1708 "iconv" iconv is supported as both a shell utility and a C RTL routine.
1709 See also the iconv(1) and iconv(3) manual pages.
1710
1711 locales Locales are supported. There may be glitches when a locale is
1712 another EBCDIC code page which has some of the code-page
1713 variant characters in other positions.
1714
1715 There aren't currently any real UTF-8 locales, even though some
1716 locale names contain the string "UTF-8".
1717
1718 See perllocale for information on locales. The L10N files are
1719 in /usr/nls/locale. $Config{d_setlocale} is 'define' on OS/390
1720 or z/OS.
1721
1722 POSIX-BC?
1723 XXX.
1724
1726 • Not all shells will allow multiple "-e" string arguments to perl to
1727 be concatenated together properly as recipes in this document 0, 2,
1728 4, 5, and 6 might seem to imply.
1729
1730 • There are a significant number of test failures in the CPAN modules
1731 shipped with Perl v5.22 and 5.24. These are only in modules not
1732 primarily maintained by Perl 5 porters. Some of these are failures
1733 in the tests only: they don't realize that it is proper to get
1734 different results on EBCDIC platforms. And some of the failures
1735 are real bugs. If you compile and do a "make test" on Perl, all
1736 tests on the "/cpan" directory are skipped.
1737
1738 Encode partially works.
1739
1740 • In earlier Perl versions, when byte and character data were
1741 concatenated, the new string was sometimes created by decoding the
1742 byte strings as ISO 8859-1 (Latin-1), even if the old Unicode
1743 string used EBCDIC.
1744
1746 perllocale, perlfunc, perlunicode, utf8.
1747
1749 <http://anubis.dkuug.dk/i18n/charmaps>
1750
1751 <https://www.unicode.org/>
1752
1753 <https://www.unicode.org/unicode/reports/tr16/>
1754
1755 <http://www.wps.com/projects/codes/> ASCII: American Standard Code for
1756 Information Infiltration Tom Jennings, September 1999.
1757
1758 The Unicode Standard, Version 3.0 The Unicode Consortium, Lisa Moore
1759 ed., ISBN 0-201-61633-5, Addison Wesley Developers Press, February
1760 2000.
1761
1762 CDRA: IBM - Character Data Representation Architecture - Reference and
1763 Registry, IBM SC09-2190-00, December 1996.
1764
1765 "Demystifying Character Sets", Andrea Vine, Multilingual Computing &
1766 Technology, #26 Vol. 10 Issue 4, August/September 1999; ISSN 1523-0309;
1767 Multilingual Computing Inc. Sandpoint ID, USA.
1768
1769 Codes, Ciphers, and Other Cryptic and Clandestine Communication Fred B.
1770 Wrixon, ISBN 1-57912-040-7, Black Dog & Leventhal Publishers, 1998.
1771
1772 <http://www.bobbemer.com/P-BIT.HTM> IBM - EBCDIC and the P-bit; The
1773 biggest Computer Goof Ever Robert Bemer.
1774
1776 15 April 2001: added UTF-8 and UTF-EBCDIC to main table, pvhp.
1777
1779 Peter Prymmer pvhp@best.com wrote this in 1999 and 2000 with CCSID 0819
1780 and 0037 help from Chris Leach and Andre Pirard A.Pirard@ulg.ac.be as
1781 well as POSIX-BC help from Thomas Dorner Thomas.Dorner@start.de.
1782 Thanks also to Vickie Cooper, Philip Newton, William Raffloer, and Joe
1783 Smith. Trademarks, registered trademarks, service marks and registered
1784 service marks used in this document are the property of their
1785 respective owners.
1786
1787 Now maintained by Perl5 Porters.
1788
1789
1790
1791perl v5.32.1 2021-05-31 PERLEBCDIC(1)