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