Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / man / man1 / perlebcdic.1
CommitLineData
920dae64
AT
1.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "PERLEBCDIC 1"
132.TH PERLEBCDIC 1 "2006-01-07" "perl v5.8.8" "Perl Programmers Reference Guide"
133.SH "NAME"
134perlebcdic \- Considerations for running Perl on EBCDIC platforms
135.SH "DESCRIPTION"
136.IX Header "DESCRIPTION"
137An exploration of some of the issues facing Perl programmers
138on \s-1EBCDIC\s0 based computers. We do not cover localization,
139internationalization, or multi byte character set issues other
140than some discussion of \s-1UTF\-8\s0 and \s-1UTF\-EBCDIC\s0.
141.PP
142Portions that are still incomplete are marked with \s-1XXX\s0.
143.SH "COMMON CHARACTER CODE SETS"
144.IX Header "COMMON CHARACTER CODE SETS"
145.Sh "\s-1ASCII\s0"
146.IX Subsection "ASCII"
147The American Standard Code for Information Interchange is a set of
148integers running from 0 to 127 (decimal) that imply character
149interpretation by the display and other system(s) of computers.
150The range 0..127 can be covered by setting the bits in a 7\-bit binary
151digit, hence the set is sometimes referred to as a \*(L"7\-bit \s-1ASCII\s0\*(R".
152\&\s-1ASCII\s0 was described by the American National Standards Institute
153document \s-1ANSI\s0 X3.4\-1986. It was also described by \s-1ISO\s0 646:1991
154(with localization for currency symbols). The full \s-1ASCII\s0 set is
155given in the table below as the first 128 elements. Languages that
156can be written adequately with the characters in \s-1ASCII\s0 include
157English, Hawaiian, Indonesian, Swahili and some Native American
158languages.
159.PP
160There are many character sets that extend the range of integers
161from 0..2**7\-1 up to 2**8\-1, or 8 bit bytes (octets if you prefer).
162One common one is the \s-1ISO\s0 8859\-1 character set.
163.Sh "\s-1ISO\s0 8859"
164.IX Subsection "ISO 8859"
165The \s-1ISO\s0 8859\-$n are a collection of character code sets from the
166International Organization for Standardization (\s-1ISO\s0) each of which
167adds characters to the \s-1ASCII\s0 set that are typically found in European
168languages many of which are based on the Roman, or Latin, alphabet.
169.Sh "Latin 1 (\s-1ISO\s0 8859\-1)"
170.IX Subsection "Latin 1 (ISO 8859-1)"
171A particular 8\-bit extension to \s-1ASCII\s0 that includes grave and acute
172accented Latin characters. Languages that can employ \s-1ISO\s0 8859\-1
173include all the languages covered by \s-1ASCII\s0 as well as Afrikaans,
174Albanian, Basque, Catalan, Danish, Faroese, Finnish, Norwegian,
175Portuguese, Spanish, and Swedish. Dutch is covered albeit without
176the ij ligature. French is covered too but without the oe ligature.
177German can use \s-1ISO\s0 8859\-1 but must do so without German-style
178quotation marks. This set is based on Western European extensions
179to \s-1ASCII\s0 and is commonly encountered in world wide web work.
180In \s-1IBM\s0 character code set identification terminology \s-1ISO\s0 8859\-1 is
181also known as \s-1CCSID\s0 819 (or sometimes 0819 or even 00819).
182.Sh "\s-1EBCDIC\s0"
183.IX Subsection "EBCDIC"
184The Extended Binary Coded Decimal Interchange Code refers to a
185large collection of slightly different single and multi byte
186coded character sets that are different from \s-1ASCII\s0 or \s-1ISO\s0 8859\-1
187and typically run on host computers. The \s-1EBCDIC\s0 encodings derive
188from 8 bit byte extensions of Hollerith punched card encodings.
189The layout on the cards was such that high bits were set for the
190upper and lower case alphabet characters [a\-z] and [A\-Z], but there
191were gaps within each latin alphabet range.
192.PP
193Some \s-1IBM\s0 \s-1EBCDIC\s0 character sets may be known by character code set
194identification numbers (\s-1CCSID\s0 numbers) or code page numbers. Leading
195zero digits in \s-1CCSID\s0 numbers within this document are insignificant.
196E.g. \s-1CCSID\s0 0037 may be referred to as 37 in places.
197.Sh "13 variant characters"
198.IX Subsection "13 variant characters"
199Among \s-1IBM\s0 \s-1EBCDIC\s0 character code sets there are 13 characters that
200are often mapped to different integer values. Those characters
201are known as the 13 \*(L"variant\*(R" characters and are:
202.PP
203.Vb 1
204\& \e [ ] { } ^ ~ ! # | $ @ `
205.Ve
206.Sh "0037"
207.IX Subsection "0037"
208Character code set \s-1ID\s0 0037 is a mapping of the \s-1ASCII\s0 plus Latin\-1
209characters (i.e. \s-1ISO\s0 8859\-1) to an \s-1EBCDIC\s0 set. 0037 is used
210in North American English locales on the \s-1OS/400\s0 operating system
211that runs on \s-1AS/400\s0 computers. \s-1CCSID\s0 37 differs from \s-1ISO\s0 8859\-1
212in 237 places, in other words they agree on only 19 code point values.
213.Sh "1047"
214.IX Subsection "1047"
215Character code set \s-1ID\s0 1047 is also a mapping of the \s-1ASCII\s0 plus
216Latin\-1 characters (i.e. \s-1ISO\s0 8859\-1) to an \s-1EBCDIC\s0 set. 1047 is
217used under Unix System Services for \s-1OS/390\s0 or z/OS, and OpenEdition
218for \s-1VM/ESA\s0. \s-1CCSID\s0 1047 differs from \s-1CCSID\s0 0037 in eight places.
219.Sh "POSIX-BC"
220.IX Subsection "POSIX-BC"
221The \s-1EBCDIC\s0 code page in use on Siemens' \s-1BS2000\s0 system is distinct from
2221047 and 0037. It is identified below as the POSIX-BC set.
223.Sh "Unicode code points versus \s-1EBCDIC\s0 code points"
224.IX Subsection "Unicode code points versus EBCDIC code points"
225In Unicode terminology a \fIcode point\fR is the number assigned to a
226character: for example, in \s-1EBCDIC\s0 the character \*(L"A\*(R" is usually assigned
227the number 193. In Unicode the character \*(L"A\*(R" is assigned the number 65.
228This causes a problem with the semantics of the pack/unpack \*(L"U\*(R", which
229are supposed to pack Unicode code points to characters and back to numbers.
230The problem is: which code points to use for code points less than 256?
231(for 256 and over there's no problem: Unicode code points are used)
232In \s-1EBCDIC\s0, for the low 256 the \s-1EBCDIC\s0 code points are used. This
233means that the equivalences
234.PP
235.Vb 2
236\& pack("U", ord($character)) eq $character
237\& unpack("U", $character) == ord $character
238.Ve
239.PP
240will hold. (If Unicode code points were applied consistently over
241all the possible code points, pack(\*(L"U\*(R",ord(\*(L"A\*(R")) would in \s-1EBCDIC\s0
242equal \fIA with acute\fR or chr(101), and unpack(\*(L"U\*(R", \*(L"A\*(R") would equal
24365, or \fInon-breaking space\fR, not 193, or ord \*(L"A\*(R".)
244.Sh "Remaining Perl Unicode problems in \s-1EBCDIC\s0"
245.IX Subsection "Remaining Perl Unicode problems in EBCDIC"
246.IP "\(bu" 4
247Many of the remaining seem to be related to case-insensitive matching:
248for example, \f(CW\*(C`/[\ex{131}]/\*(C'\fR (\s-1LATIN\s0 \s-1SMALL\s0 \s-1LETTER\s0 \s-1DOTLESS\s0 I) does
249not match \*(L"I\*(R" case\-insensitively, as it should under Unicode.
250(The match succeeds in ASCII-derived platforms.)
251.IP "\(bu" 4
252The extensions Unicode::Collate and Unicode::Normalized are not
253supported under \s-1EBCDIC\s0, likewise for the encoding pragma.
254.Sh "Unicode and \s-1UTF\s0"
255.IX Subsection "Unicode and UTF"
256\&\s-1UTF\s0 is a Unicode Transformation Format. \s-1UTF\-8\s0 is a Unicode conforming
257representation of the Unicode standard that looks very much like \s-1ASCII\s0.
258UTF-EBCDIC is an attempt to represent Unicode characters in an \s-1EBCDIC\s0
259transparent manner.
260.Sh "Using Encode"
261.IX Subsection "Using Encode"
262Starting from Perl 5.8 you can use the standard new module Encode
263to translate from \s-1EBCDIC\s0 to Latin\-1 code points
264.PP
265.Vb 1
266\& use Encode 'from_to';
267.Ve
268.PP
269.Vb 1
270\& my %ebcdic = ( 176 => 'cp37', 95 => 'cp1047', 106 => 'posix-bc' );
271.Ve
272.PP
273.Vb 3
274\& # $a is in EBCDIC code points
275\& from_to($a, $ebcdic{ord '^'}, 'latin1');
276\& # $a is ISO 8859-1 code points
277.Ve
278.PP
279and from Latin\-1 code points to \s-1EBCDIC\s0 code points
280.PP
281.Vb 1
282\& use Encode 'from_to';
283.Ve
284.PP
285.Vb 1
286\& my %ebcdic = ( 176 => 'cp37', 95 => 'cp1047', 106 => 'posix-bc' );
287.Ve
288.PP
289.Vb 3
290\& # $a is ISO 8859-1 code points
291\& from_to($a, 'latin1', $ebcdic{ord '^'});
292\& # $a is in EBCDIC code points
293.Ve
294.PP
295For doing I/O it is suggested that you use the autotranslating features
296of PerlIO, see perluniintro.
297.PP
298Since version 5.8 Perl uses the new PerlIO I/O library. This enables
299you to use different encodings per \s-1IO\s0 channel. For example you may use
300.PP
301.Vb 9
302\& use Encode;
303\& open($f, ">:encoding(ascii)", "test.ascii");
304\& print $f "Hello World!\en";
305\& open($f, ">:encoding(cp37)", "test.ebcdic");
306\& print $f "Hello World!\en";
307\& open($f, ">:encoding(latin1)", "test.latin1");
308\& print $f "Hello World!\en";
309\& open($f, ">:encoding(utf8)", "test.utf8");
310\& print $f "Hello World!\en";
311.Ve
312.PP
313to get two files containing \*(L"Hello World!\en\*(R" in \s-1ASCII\s0, \s-1CP\s0 37 \s-1EBCDIC\s0,
314\&\s-1ISO\s0 8859\-1 (Latin\-1) (in this example identical to \s-1ASCII\s0) respective
315UTF-EBCDIC (in this example identical to normal \s-1EBCDIC\s0). See the
316documentation of Encode::PerlIO for details.
317.PP
318As the PerlIO layer uses raw \s-1IO\s0 (bytes) internally, all this totally
319ignores things like the type of your filesystem (\s-1ASCII\s0 or \s-1EBCDIC\s0).
320.SH "SINGLE OCTET TABLES"
321.IX Header "SINGLE OCTET TABLES"
322The following tables list the \s-1ASCII\s0 and Latin 1 ordered sets including
323the subsets: C0 controls (0..31), \s-1ASCII\s0 graphics (32..7e), delete (7f),
324C1 controls (80..9f), and Latin\-1 (a.k.a. \s-1ISO\s0 8859\-1) (a0..ff). In the
325table non-printing control character names as well as the Latin 1
326extensions to \s-1ASCII\s0 have been labelled with character names roughly
327corresponding to \fIThe Unicode Standard, Version 3.0\fR albeit with
328substitutions such as s/LATIN// and s/VULGAR// in all cases,
329s/CAPITAL \s-1LETTER//\s0 in some cases, and s/SMALL \s-1LETTER\s0 ([A\-Z])/\el$1/
330in some other cases (the \f(CW\*(C`charnames\*(C'\fR pragma names unfortunately do
331not list explicit names for the C0 or C1 control characters). The
332\&\*(L"names\*(R" of the C1 control set (128..159 in \s-1ISO\s0 8859\-1) listed here are
333somewhat arbitrary. The differences between the 0037 and 1047 sets are
334flagged with ***. The differences between the 1047 and POSIX-BC sets
335are flagged with ###. All \fIord()\fR numbers listed are decimal. If you
336would rather see this table listing octal values then run the table
337(that is, the pod version of this document since this recipe may not
338work with a pod2_other_format translation) through:
339.IP "recipe 0" 4
340.IX Item "recipe 0"
341.PP
342.Vb 2
343\& perl -ne 'if(/(.{33})(\ed+)\es+(\ed+)\es+(\ed+)\es+(\ed+)/)' \e
344\& -e '{printf("%s%-9o%-9o%-9o%o\en",$1,$2,$3,$4,$5)}' perlebcdic.pod
345.Ve
346.PP
347If you want to retain the UTF-x code points then in script form you
348might want to write:
349.IP "recipe 1" 4
350.IX Item "recipe 1"
351.PP
352.Vb 14
353\& open(FH,"<perlebcdic.pod") or die "Could not open perlebcdic.pod: $!";
354\& while (<FH>) {
355\& if (/(.{33})(\ed+)\es+(\ed+)\es+(\ed+)\es+(\ed+)\es+(\ed+)\e.?(\ed*)\es+(\ed+)\e.?(\ed*)/) {
356\& if ($7 ne '' && $9 ne '') {
357\& printf("%s%-9o%-9o%-9o%-9o%-3o.%-5o%-3o.%o\en",$1,$2,$3,$4,$5,$6,$7,$8,$9);
358\& }
359\& elsif ($7 ne '') {
360\& printf("%s%-9o%-9o%-9o%-9o%-3o.%-5o%o\en",$1,$2,$3,$4,$5,$6,$7,$8);
361\& }
362\& else {
363\& printf("%s%-9o%-9o%-9o%-9o%-9o%o\en",$1,$2,$3,$4,$5,$6,$8);
364\& }
365\& }
366\& }
367.Ve
368.PP
369If you would rather see this table listing hexadecimal values then
370run the table through:
371.IP "recipe 2" 4
372.IX Item "recipe 2"
373.PP
374.Vb 2
375\& perl -ne 'if(/(.{33})(\ed+)\es+(\ed+)\es+(\ed+)\es+(\ed+)/)' \e
376\& -e '{printf("%s%-9X%-9X%-9X%X\en",$1,$2,$3,$4,$5)}' perlebcdic.pod
377.Ve
378.PP
379Or, in order to retain the UTF-x code points in hexadecimal:
380.IP "recipe 3" 4
381.IX Item "recipe 3"
382.PP
383.Vb 14
384\& open(FH,"<perlebcdic.pod") or die "Could not open perlebcdic.pod: $!";
385\& while (<FH>) {
386\& if (/(.{33})(\ed+)\es+(\ed+)\es+(\ed+)\es+(\ed+)\es+(\ed+)\e.?(\ed*)\es+(\ed+)\e.?(\ed*)/) {
387\& if ($7 ne '' && $9 ne '') {
388\& printf("%s%-9X%-9X%-9X%-9X%-2X.%-6X%-2X.%X\en",$1,$2,$3,$4,$5,$6,$7,$8,$9);
389\& }
390\& elsif ($7 ne '') {
391\& printf("%s%-9X%-9X%-9X%-9X%-2X.%-6X%X\en",$1,$2,$3,$4,$5,$6,$7,$8);
392\& }
393\& else {
394\& printf("%s%-9X%-9X%-9X%-9X%-9X%X\en",$1,$2,$3,$4,$5,$6,$8);
395\& }
396\& }
397\& }
398.Ve
399.PP
400.Vb 260
401\& incomp- incomp-
402\& 8859-1 lete lete
403\& chr 0819 0037 1047 POSIX-BC UTF-8 UTF-EBCDIC
404\& ------------------------------------------------------------------------------------
405\& <NULL> 0 0 0 0 0 0
406\& <START OF HEADING> 1 1 1 1 1 1
407\& <START OF TEXT> 2 2 2 2 2 2
408\& <END OF TEXT> 3 3 3 3 3 3
409\& <END OF TRANSMISSION> 4 55 55 55 4 55
410\& <ENQUIRY> 5 45 45 45 5 45
411\& <ACKNOWLEDGE> 6 46 46 46 6 46
412\& <BELL> 7 47 47 47 7 47
413\& <BACKSPACE> 8 22 22 22 8 22
414\& <HORIZONTAL TABULATION> 9 5 5 5 9 5
415\& <LINE FEED> 10 37 21 21 10 21 ***
416\& <VERTICAL TABULATION> 11 11 11 11 11 11
417\& <FORM FEED> 12 12 12 12 12 12
418\& <CARRIAGE RETURN> 13 13 13 13 13 13
419\& <SHIFT OUT> 14 14 14 14 14 14
420\& <SHIFT IN> 15 15 15 15 15 15
421\& <DATA LINK ESCAPE> 16 16 16 16 16 16
422\& <DEVICE CONTROL ONE> 17 17 17 17 17 17
423\& <DEVICE CONTROL TWO> 18 18 18 18 18 18
424\& <DEVICE CONTROL THREE> 19 19 19 19 19 19
425\& <DEVICE CONTROL FOUR> 20 60 60 60 20 60
426\& <NEGATIVE ACKNOWLEDGE> 21 61 61 61 21 61
427\& <SYNCHRONOUS IDLE> 22 50 50 50 22 50
428\& <END OF TRANSMISSION BLOCK> 23 38 38 38 23 38
429\& <CANCEL> 24 24 24 24 24 24
430\& <END OF MEDIUM> 25 25 25 25 25 25
431\& <SUBSTITUTE> 26 63 63 63 26 63
432\& <ESCAPE> 27 39 39 39 27 39
433\& <FILE SEPARATOR> 28 28 28 28 28 28
434\& <GROUP SEPARATOR> 29 29 29 29 29 29
435\& <RECORD SEPARATOR> 30 30 30 30 30 30
436\& <UNIT SEPARATOR> 31 31 31 31 31 31
437\& <SPACE> 32 64 64 64 32 64
438\& ! 33 90 90 90 33 90
439\& " 34 127 127 127 34 127
440\& # 35 123 123 123 35 123
441\& $ 36 91 91 91 36 91
442\& % 37 108 108 108 37 108
443\& & 38 80 80 80 38 80
444\& ' 39 125 125 125 39 125
445\& ( 40 77 77 77 40 77
446\& ) 41 93 93 93 41 93
447\& * 42 92 92 92 42 92
448\& + 43 78 78 78 43 78
449\& , 44 107 107 107 44 107
450\& - 45 96 96 96 45 96
451\& . 46 75 75 75 46 75
452\& / 47 97 97 97 47 97
453\& 0 48 240 240 240 48 240
454\& 1 49 241 241 241 49 241
455\& 2 50 242 242 242 50 242
456\& 3 51 243 243 243 51 243
457\& 4 52 244 244 244 52 244
458\& 5 53 245 245 245 53 245
459\& 6 54 246 246 246 54 246
460\& 7 55 247 247 247 55 247
461\& 8 56 248 248 248 56 248
462\& 9 57 249 249 249 57 249
463\& : 58 122 122 122 58 122
464\& ; 59 94 94 94 59 94
465\& < 60 76 76 76 60 76
466\& = 61 126 126 126 61 126
467\& > 62 110 110 110 62 110
468\& ? 63 111 111 111 63 111
469\& @ 64 124 124 124 64 124
470\& A 65 193 193 193 65 193
471\& B 66 194 194 194 66 194
472\& C 67 195 195 195 67 195
473\& D 68 196 196 196 68 196
474\& E 69 197 197 197 69 197
475\& F 70 198 198 198 70 198
476\& G 71 199 199 199 71 199
477\& H 72 200 200 200 72 200
478\& I 73 201 201 201 73 201
479\& J 74 209 209 209 74 209
480\& K 75 210 210 210 75 210
481\& L 76 211 211 211 76 211
482\& M 77 212 212 212 77 212
483\& N 78 213 213 213 78 213
484\& O 79 214 214 214 79 214
485\& P 80 215 215 215 80 215
486\& Q 81 216 216 216 81 216
487\& R 82 217 217 217 82 217
488\& S 83 226 226 226 83 226
489\& T 84 227 227 227 84 227
490\& U 85 228 228 228 85 228
491\& V 86 229 229 229 86 229
492\& W 87 230 230 230 87 230
493\& X 88 231 231 231 88 231
494\& Y 89 232 232 232 89 232
495\& Z 90 233 233 233 90 233
496\& [ 91 186 173 187 91 173 *** ###
497\& \e 92 224 224 188 92 224 ###
498\& ] 93 187 189 189 93 189 ***
499\& ^ 94 176 95 106 94 95 *** ###
500\& _ 95 109 109 109 95 109
501\& ` 96 121 121 74 96 121 ###
502\& a 97 129 129 129 97 129
503\& b 98 130 130 130 98 130
504\& c 99 131 131 131 99 131
505\& d 100 132 132 132 100 132
506\& e 101 133 133 133 101 133
507\& f 102 134 134 134 102 134
508\& g 103 135 135 135 103 135
509\& h 104 136 136 136 104 136
510\& i 105 137 137 137 105 137
511\& j 106 145 145 145 106 145
512\& k 107 146 146 146 107 146
513\& l 108 147 147 147 108 147
514\& m 109 148 148 148 109 148
515\& n 110 149 149 149 110 149
516\& o 111 150 150 150 111 150
517\& p 112 151 151 151 112 151
518\& q 113 152 152 152 113 152
519\& r 114 153 153 153 114 153
520\& s 115 162 162 162 115 162
521\& t 116 163 163 163 116 163
522\& u 117 164 164 164 117 164
523\& v 118 165 165 165 118 165
524\& w 119 166 166 166 119 166
525\& x 120 167 167 167 120 167
526\& y 121 168 168 168 121 168
527\& z 122 169 169 169 122 169
528\& { 123 192 192 251 123 192 ###
529\& | 124 79 79 79 124 79
530\& } 125 208 208 253 125 208 ###
531\& ~ 126 161 161 255 126 161 ###
532\& <DELETE> 127 7 7 7 127 7
533\& <C1 0> 128 32 32 32 194.128 32
534\& <C1 1> 129 33 33 33 194.129 33
535\& <C1 2> 130 34 34 34 194.130 34
536\& <C1 3> 131 35 35 35 194.131 35
537\& <C1 4> 132 36 36 36 194.132 36
538\& <C1 5> 133 21 37 37 194.133 37 ***
539\& <C1 6> 134 6 6 6 194.134 6
540\& <C1 7> 135 23 23 23 194.135 23
541\& <C1 8> 136 40 40 40 194.136 40
542\& <C1 9> 137 41 41 41 194.137 41
543\& <C1 10> 138 42 42 42 194.138 42
544\& <C1 11> 139 43 43 43 194.139 43
545\& <C1 12> 140 44 44 44 194.140 44
546\& <C1 13> 141 9 9 9 194.141 9
547\& <C1 14> 142 10 10 10 194.142 10
548\& <C1 15> 143 27 27 27 194.143 27
549\& <C1 16> 144 48 48 48 194.144 48
550\& <C1 17> 145 49 49 49 194.145 49
551\& <C1 18> 146 26 26 26 194.146 26
552\& <C1 19> 147 51 51 51 194.147 51
553\& <C1 20> 148 52 52 52 194.148 52
554\& <C1 21> 149 53 53 53 194.149 53
555\& <C1 22> 150 54 54 54 194.150 54
556\& <C1 23> 151 8 8 8 194.151 8
557\& <C1 24> 152 56 56 56 194.152 56
558\& <C1 25> 153 57 57 57 194.153 57
559\& <C1 26> 154 58 58 58 194.154 58
560\& <C1 27> 155 59 59 59 194.155 59
561\& <C1 28> 156 4 4 4 194.156 4
562\& <C1 29> 157 20 20 20 194.157 20
563\& <C1 30> 158 62 62 62 194.158 62
564\& <C1 31> 159 255 255 95 194.159 255 ###
565\& <NON-BREAKING SPACE> 160 65 65 65 194.160 128.65
566\& <INVERTED EXCLAMATION MARK> 161 170 170 170 194.161 128.66
567\& <CENT SIGN> 162 74 74 176 194.162 128.67 ###
568\& <POUND SIGN> 163 177 177 177 194.163 128.68
569\& <CURRENCY SIGN> 164 159 159 159 194.164 128.69
570\& <YEN SIGN> 165 178 178 178 194.165 128.70
571\& <BROKEN BAR> 166 106 106 208 194.166 128.71 ###
572\& <SECTION SIGN> 167 181 181 181 194.167 128.72
573\& <DIAERESIS> 168 189 187 121 194.168 128.73 *** ###
574\& <COPYRIGHT SIGN> 169 180 180 180 194.169 128.74
575\& <FEMININE ORDINAL INDICATOR> 170 154 154 154 194.170 128.81
576\& <LEFT POINTING GUILLEMET> 171 138 138 138 194.171 128.82
577\& <NOT SIGN> 172 95 176 186 194.172 128.83 *** ###
578\& <SOFT HYPHEN> 173 202 202 202 194.173 128.84
579\& <REGISTERED TRADE MARK SIGN> 174 175 175 175 194.174 128.85
580\& <MACRON> 175 188 188 161 194.175 128.86 ###
581\& <DEGREE SIGN> 176 144 144 144 194.176 128.87
582\& <PLUS-OR-MINUS SIGN> 177 143 143 143 194.177 128.88
583\& <SUPERSCRIPT TWO> 178 234 234 234 194.178 128.89
584\& <SUPERSCRIPT THREE> 179 250 250 250 194.179 128.98
585\& <ACUTE ACCENT> 180 190 190 190 194.180 128.99
586\& <MICRO SIGN> 181 160 160 160 194.181 128.100
587\& <PARAGRAPH SIGN> 182 182 182 182 194.182 128.101
588\& <MIDDLE DOT> 183 179 179 179 194.183 128.102
589\& <CEDILLA> 184 157 157 157 194.184 128.103
590\& <SUPERSCRIPT ONE> 185 218 218 218 194.185 128.104
591\& <MASC. ORDINAL INDICATOR> 186 155 155 155 194.186 128.105
592\& <RIGHT POINTING GUILLEMET> 187 139 139 139 194.187 128.106
593\& <FRACTION ONE QUARTER> 188 183 183 183 194.188 128.112
594\& <FRACTION ONE HALF> 189 184 184 184 194.189 128.113
595\& <FRACTION THREE QUARTERS> 190 185 185 185 194.190 128.114
596\& <INVERTED QUESTION MARK> 191 171 171 171 194.191 128.115
597\& <A WITH GRAVE> 192 100 100 100 195.128 138.65
598\& <A WITH ACUTE> 193 101 101 101 195.129 138.66
599\& <A WITH CIRCUMFLEX> 194 98 98 98 195.130 138.67
600\& <A WITH TILDE> 195 102 102 102 195.131 138.68
601\& <A WITH DIAERESIS> 196 99 99 99 195.132 138.69
602\& <A WITH RING ABOVE> 197 103 103 103 195.133 138.70
603\& <CAPITAL LIGATURE AE> 198 158 158 158 195.134 138.71
604\& <C WITH CEDILLA> 199 104 104 104 195.135 138.72
605\& <E WITH GRAVE> 200 116 116 116 195.136 138.73
606\& <E WITH ACUTE> 201 113 113 113 195.137 138.74
607\& <E WITH CIRCUMFLEX> 202 114 114 114 195.138 138.81
608\& <E WITH DIAERESIS> 203 115 115 115 195.139 138.82
609\& <I WITH GRAVE> 204 120 120 120 195.140 138.83
610\& <I WITH ACUTE> 205 117 117 117 195.141 138.84
611\& <I WITH CIRCUMFLEX> 206 118 118 118 195.142 138.85
612\& <I WITH DIAERESIS> 207 119 119 119 195.143 138.86
613\& <CAPITAL LETTER ETH> 208 172 172 172 195.144 138.87
614\& <N WITH TILDE> 209 105 105 105 195.145 138.88
615\& <O WITH GRAVE> 210 237 237 237 195.146 138.89
616\& <O WITH ACUTE> 211 238 238 238 195.147 138.98
617\& <O WITH CIRCUMFLEX> 212 235 235 235 195.148 138.99
618\& <O WITH TILDE> 213 239 239 239 195.149 138.100
619\& <O WITH DIAERESIS> 214 236 236 236 195.150 138.101
620\& <MULTIPLICATION SIGN> 215 191 191 191 195.151 138.102
621\& <O WITH STROKE> 216 128 128 128 195.152 138.103
622\& <U WITH GRAVE> 217 253 253 224 195.153 138.104 ###
623\& <U WITH ACUTE> 218 254 254 254 195.154 138.105
624\& <U WITH CIRCUMFLEX> 219 251 251 221 195.155 138.106 ###
625\& <U WITH DIAERESIS> 220 252 252 252 195.156 138.112
626\& <Y WITH ACUTE> 221 173 186 173 195.157 138.113 *** ###
627\& <CAPITAL LETTER THORN> 222 174 174 174 195.158 138.114
628\& <SMALL LETTER SHARP S> 223 89 89 89 195.159 138.115
629\& <a WITH GRAVE> 224 68 68 68 195.160 139.65
630\& <a WITH ACUTE> 225 69 69 69 195.161 139.66
631\& <a WITH CIRCUMFLEX> 226 66 66 66 195.162 139.67
632\& <a WITH TILDE> 227 70 70 70 195.163 139.68
633\& <a WITH DIAERESIS> 228 67 67 67 195.164 139.69
634\& <a WITH RING ABOVE> 229 71 71 71 195.165 139.70
635\& <SMALL LIGATURE ae> 230 156 156 156 195.166 139.71
636\& <c WITH CEDILLA> 231 72 72 72 195.167 139.72
637\& <e WITH GRAVE> 232 84 84 84 195.168 139.73
638\& <e WITH ACUTE> 233 81 81 81 195.169 139.74
639\& <e WITH CIRCUMFLEX> 234 82 82 82 195.170 139.81
640\& <e WITH DIAERESIS> 235 83 83 83 195.171 139.82
641\& <i WITH GRAVE> 236 88 88 88 195.172 139.83
642\& <i WITH ACUTE> 237 85 85 85 195.173 139.84
643\& <i WITH CIRCUMFLEX> 238 86 86 86 195.174 139.85
644\& <i WITH DIAERESIS> 239 87 87 87 195.175 139.86
645\& <SMALL LETTER eth> 240 140 140 140 195.176 139.87
646\& <n WITH TILDE> 241 73 73 73 195.177 139.88
647\& <o WITH GRAVE> 242 205 205 205 195.178 139.89
648\& <o WITH ACUTE> 243 206 206 206 195.179 139.98
649\& <o WITH CIRCUMFLEX> 244 203 203 203 195.180 139.99
650\& <o WITH TILDE> 245 207 207 207 195.181 139.100
651\& <o WITH DIAERESIS> 246 204 204 204 195.182 139.101
652\& <DIVISION SIGN> 247 225 225 225 195.183 139.102
653\& <o WITH STROKE> 248 112 112 112 195.184 139.103
654\& <u WITH GRAVE> 249 221 221 192 195.185 139.104 ###
655\& <u WITH ACUTE> 250 222 222 222 195.186 139.105
656\& <u WITH CIRCUMFLEX> 251 219 219 219 195.187 139.106
657\& <u WITH DIAERESIS> 252 220 220 220 195.188 139.112
658\& <y WITH ACUTE> 253 141 141 141 195.189 139.113
659\& <SMALL LETTER thorn> 254 142 142 142 195.190 139.114
660\& <y WITH DIAERESIS> 255 223 223 223 195.191 139.115
661.Ve
662.PP
663If you would rather see the above table in \s-1CCSID\s0 0037 order rather than
664\&\s-1ASCII\s0 + Latin\-1 order then run the table through:
665.IP "recipe 4" 4
666.IX Item "recipe 4"
667.PP
668.Vb 5
669\& perl -ne 'if(/.{33}\ed{1,3}\es{6,8}\ed{1,3}\es{6,8}\ed{1,3}\es{6,8}\ed{1,3}/)'\e
670\& -e '{push(@l,$_)}' \e
671\& -e 'END{print map{$_->[0]}' \e
672\& -e ' sort{$a->[1] <=> $b->[1]}' \e
673\& -e ' map{[$_,substr($_,42,3)]}@l;}' perlebcdic.pod
674.Ve
675.PP
676If you would rather see it in \s-1CCSID\s0 1047 order then change the digit
67742 in the last line to 51, like this:
678.IP "recipe 5" 4
679.IX Item "recipe 5"
680.PP
681.Vb 5
682\& perl -ne 'if(/.{33}\ed{1,3}\es{6,8}\ed{1,3}\es{6,8}\ed{1,3}\es{6,8}\ed{1,3}/)'\e
683\& -e '{push(@l,$_)}' \e
684\& -e 'END{print map{$_->[0]}' \e
685\& -e ' sort{$a->[1] <=> $b->[1]}' \e
686\& -e ' map{[$_,substr($_,51,3)]}@l;}' perlebcdic.pod
687.Ve
688.PP
689If you would rather see it in POSIX-BC order then change the digit
69051 in the last line to 60, like this:
691.IP "recipe 6" 4
692.IX Item "recipe 6"
693.PP
694.Vb 5
695\& perl -ne 'if(/.{33}\ed{1,3}\es{6,8}\ed{1,3}\es{6,8}\ed{1,3}\es{6,8}\ed{1,3}/)'\e
696\& -e '{push(@l,$_)}' \e
697\& -e 'END{print map{$_->[0]}' \e
698\& -e ' sort{$a->[1] <=> $b->[1]}' \e
699\& -e ' map{[$_,substr($_,60,3)]}@l;}' perlebcdic.pod
700.Ve
701.SH "IDENTIFYING CHARACTER CODE SETS"
702.IX Header "IDENTIFYING CHARACTER CODE SETS"
703To determine the character set you are running under from perl one
704could use the return value of \fIord()\fR or \fIchr()\fR to test one or more
705character values. For example:
706.PP
707.Vb 2
708\& $is_ascii = "A" eq chr(65);
709\& $is_ebcdic = "A" eq chr(193);
710.Ve
711.PP
712Also, \*(L"\et\*(R" is a \f(CW\*(C`HORIZONTAL TABULATION\*(C'\fR character so that:
713.PP
714.Vb 2
715\& $is_ascii = ord("\et") == 9;
716\& $is_ebcdic = ord("\et") == 5;
717.Ve
718.PP
719To distinguish \s-1EBCDIC\s0 code pages try looking at one or more of
720the characters that differ between them. For example:
721.PP
722.Vb 2
723\& $is_ebcdic_37 = "\en" eq chr(37);
724\& $is_ebcdic_1047 = "\en" eq chr(21);
725.Ve
726.PP
727Or better still choose a character that is uniquely encoded in any
728of the code sets, e.g.:
729.PP
730.Vb 4
731\& $is_ascii = ord('[') == 91;
732\& $is_ebcdic_37 = ord('[') == 186;
733\& $is_ebcdic_1047 = ord('[') == 173;
734\& $is_ebcdic_POSIX_BC = ord('[') == 187;
735.Ve
736.PP
737However, it would be unwise to write tests such as:
738.PP
739.Vb 2
740\& $is_ascii = "\er" ne chr(13); # WRONG
741\& $is_ascii = "\en" ne chr(10); # ILL ADVISED
742.Ve
743.PP
744Obviously the first of these will fail to distinguish most \s-1ASCII\s0 machines
745from either a \s-1CCSID\s0 0037, a 1047, or a POSIX-BC \s-1EBCDIC\s0 machine since \*(L"\er\*(R" eq
746chr(13) under all of those coded character sets. But note too that
747because \*(L"\en\*(R" is chr(13) and \*(L"\er\*(R" is chr(10) on the MacIntosh (which is an
748\&\s-1ASCII\s0 machine) the second \f(CW$is_ascii\fR test will lead to trouble there.
749.PP
750To determine whether or not perl was built under an \s-1EBCDIC\s0
751code page you can use the Config module like so:
752.PP
753.Vb 2
754\& use Config;
755\& $is_ebcdic = $Config{'ebcdic'} eq 'define';
756.Ve
757.SH "CONVERSIONS"
758.IX Header "CONVERSIONS"
759.Sh "tr///"
760.IX Subsection "tr///"
761In order to convert a string of characters from one character set to
762another a simple list of numbers, such as in the right columns in the
763above table, along with perl's tr/// operator is all that is needed.
764The data in the table are in \s-1ASCII\s0 order hence the \s-1EBCDIC\s0 columns
765provide easy to use \s-1ASCII\s0 to \s-1EBCDIC\s0 operations that are also easily
766reversed.
767.PP
768For example, to convert \s-1ASCII\s0 to code page 037 take the output of the second
769column from the output of recipe 0 (modified to add \e\e characters) and use
770it in tr/// like so:
771.PP
772.Vb 17
773\& $cp_037 =
774\& '\e000\e001\e002\e003\e234\e011\e206\e177\e227\e215\e216\e013\e014\e015\e016\e017' .
775\& '\e020\e021\e022\e023\e235\e205\e010\e207\e030\e031\e222\e217\e034\e035\e036\e037' .
776\& '\e200\e201\e202\e203\e204\e012\e027\e033\e210\e211\e212\e213\e214\e005\e006\e007' .
777\& '\e220\e221\e026\e223\e224\e225\e226\e004\e230\e231\e232\e233\e024\e025\e236\e032' .
778\& '\e040\e240\e342\e344\e340\e341\e343\e345\e347\e361\e242\e056\e074\e050\e053\e174' .
779\& '\e046\e351\e352\e353\e350\e355\e356\e357\e354\e337\e041\e044\e052\e051\e073\e254' .
780\& '\e055\e057\e302\e304\e300\e301\e303\e305\e307\e321\e246\e054\e045\e137\e076\e077' .
781\& '\e370\e311\e312\e313\e310\e315\e316\e317\e314\e140\e072\e043\e100\e047\e075\e042' .
782\& '\e330\e141\e142\e143\e144\e145\e146\e147\e150\e151\e253\e273\e360\e375\e376\e261' .
783\& '\e260\e152\e153\e154\e155\e156\e157\e160\e161\e162\e252\e272\e346\e270\e306\e244' .
784\& '\e265\e176\e163\e164\e165\e166\e167\e170\e171\e172\e241\e277\e320\e335\e336\e256' .
785\& '\e136\e243\e245\e267\e251\e247\e266\e274\e275\e276\e133\e135\e257\e250\e264\e327' .
786\& '\e173\e101\e102\e103\e104\e105\e106\e107\e110\e111\e255\e364\e366\e362\e363\e365' .
787\& '\e175\e112\e113\e114\e115\e116\e117\e120\e121\e122\e271\e373\e374\e371\e372\e377' .
788\& '\e134\e367\e123\e124\e125\e126\e127\e130\e131\e132\e262\e324\e326\e322\e323\e325' .
789\& '\e060\e061\e062\e063\e064\e065\e066\e067\e070\e071\e263\e333\e334\e331\e332\e237' ;
790.Ve
791.PP
792.Vb 2
793\& my $ebcdic_string = $ascii_string;
794\& eval '$ebcdic_string =~ tr/' . $cp_037 . '/\e000-\e377/';
795.Ve
796.PP
797To convert from \s-1EBCDIC\s0 037 to \s-1ASCII\s0 just reverse the order of the tr///
798arguments like so:
799.PP
800.Vb 2
801\& my $ascii_string = $ebcdic_string;
802\& eval '$ascii_string =~ tr/\e000-\e377/' . $cp_037 . '/';
803.Ve
804.PP
805Similarly one could take the output of the third column from recipe 0 to
806obtain a \f(CW$cp_1047\fR table. The fourth column of the output from recipe
8070 could provide a \f(CW$cp_posix_bc\fR table suitable for transcoding as well.
808.Sh "iconv"
809.IX Subsection "iconv"
810\&\s-1XPG\s0 operability often implies the presence of an \fIiconv\fR utility
811available from the shell or from the C library. Consult your system's
812documentation for information on iconv.
813.PP
814On \s-1OS/390\s0 or z/OS see the \fIiconv\fR\|(1) manpage. One way to invoke the iconv
815shell utility from within perl would be to:
816.PP
817.Vb 2
818\& # OS/390 or z/OS example
819\& $ascii_data = `echo '$ebcdic_data'| iconv -f IBM-1047 -t ISO8859-1`
820.Ve
821.PP
822or the inverse map:
823.PP
824.Vb 2
825\& # OS/390 or z/OS example
826\& $ebcdic_data = `echo '$ascii_data'| iconv -f ISO8859-1 -t IBM-1047`
827.Ve
828.PP
829For other perl based conversion options see the Convert::* modules on \s-1CPAN\s0.
830.Sh "C \s-1RTL\s0"
831.IX Subsection "C RTL"
832The \s-1OS/390\s0 and z/OS C run time libraries provide \fI_atoe()\fR and \fI_etoa()\fR functions.
833.SH "OPERATOR DIFFERENCES"
834.IX Header "OPERATOR DIFFERENCES"
835The \f(CW\*(C`..\*(C'\fR range operator treats certain character ranges with
836care on \s-1EBCDIC\s0 machines. For example the following array
837will have twenty six elements on either an \s-1EBCDIC\s0 machine
838or an \s-1ASCII\s0 machine:
839.PP
840.Vb 1
841\& @alphabet = ('A'..'Z'); # $#alphabet == 25
842.Ve
843.PP
844The bitwise operators such as & ^ | may return different results
845when operating on string or character data in a perl program running
846on an \s-1EBCDIC\s0 machine than when run on an \s-1ASCII\s0 machine. Here is
847an example adapted from the one in perlop:
848.PP
849.Vb 5
850\& # EBCDIC-based examples
851\& print "j p \en" ^ " a h"; # prints "JAPH\en"
852\& print "JA" | " ph\en"; # prints "japh\en"
853\& print "JAPH\enJunk" & "\e277\e277\e277\e277\e277"; # prints "japh\en";
854\& print 'p N$' ^ " E<H\en"; # prints "Perl\en";
855.Ve
856.PP
857An interesting property of the 32 C0 control characters
858in the \s-1ASCII\s0 table is that they can \*(L"literally\*(R" be constructed
859as control characters in perl, e.g. \f(CW\*(C`(chr(0) eq "\ec@")\*(C'\fR
860\&\f(CW\*(C`(chr(1) eq "\ecA")\*(C'\fR, and so on. Perl on \s-1EBCDIC\s0 machines has been
861ported to take \*(L"\ec@\*(R" to \fIchr\fR\|(0) and \*(L"\ecA\*(R" to \fIchr\fR\|(1) as well, but the
862thirty three characters that result depend on which code page you are
863using. The table below uses the character names from the previous table
864but with substitutions such as s/START \s-1OF/S\s0.O./; s/END \s-1OF\s0 /E.O./;
865s/TRANSMISSION/TRANS./; s/TABULATION/TAB./; s/VERTICAL/VERT./;
866s/HORIZONTAL/HORIZ./; s/DEVICE \s-1CONTROL/D\s0.C./; s/SEPARATOR/SEP./;
867s/NEGATIVE \s-1ACKNOWLEDGE/NEG\s0. \s-1ACK\s0./;. The POSIX-BC and 1047 sets are
868identical throughout this range and differ from the 0037 set at only
869one spot (21 decimal). Note that the \f(CW\*(C`LINE FEED\*(C'\fR character
870may be generated by \*(L"\ecJ\*(R" on \s-1ASCII\s0 machines but by \*(L"\ecU\*(R" on 1047 or POSIX-BC
871machines and cannot be generated as a \f(CW"\ec.letter."\fR control character on
8720037 machines. Note also that \*(L"\ec\e\e\*(R" maps to two characters
873not one.
874.PP
875.Vb 35
876\& chr ord 8859-1 0037 1047 && POSIX-BC
877\& ------------------------------------------------------------------------
878\& "\ec?" 127 <DELETE> " " ***><
879\& "\ec@" 0 <NULL> <NULL> <NULL> ***><
880\& "\ecA" 1 <S.O. HEADING> <S.O. HEADING> <S.O. HEADING>
881\& "\ecB" 2 <S.O. TEXT> <S.O. TEXT> <S.O. TEXT>
882\& "\ecC" 3 <E.O. TEXT> <E.O. TEXT> <E.O. TEXT>
883\& "\ecD" 4 <E.O. TRANS.> <C1 28> <C1 28>
884\& "\ecE" 5 <ENQUIRY> <HORIZ. TAB.> <HORIZ. TAB.>
885\& "\ecF" 6 <ACKNOWLEDGE> <C1 6> <C1 6>
886\& "\ecG" 7 <BELL> <DELETE> <DELETE>
887\& "\ecH" 8 <BACKSPACE> <C1 23> <C1 23>
888\& "\ecI" 9 <HORIZ. TAB.> <C1 13> <C1 13>
889\& "\ecJ" 10 <LINE FEED> <C1 14> <C1 14>
890\& "\ecK" 11 <VERT. TAB.> <VERT. TAB.> <VERT. TAB.>
891\& "\ecL" 12 <FORM FEED> <FORM FEED> <FORM FEED>
892\& "\ecM" 13 <CARRIAGE RETURN> <CARRIAGE RETURN> <CARRIAGE RETURN>
893\& "\ecN" 14 <SHIFT OUT> <SHIFT OUT> <SHIFT OUT>
894\& "\ecO" 15 <SHIFT IN> <SHIFT IN> <SHIFT IN>
895\& "\ecP" 16 <DATA LINK ESCAPE> <DATA LINK ESCAPE> <DATA LINK ESCAPE>
896\& "\ecQ" 17 <D.C. ONE> <D.C. ONE> <D.C. ONE>
897\& "\ecR" 18 <D.C. TWO> <D.C. TWO> <D.C. TWO>
898\& "\ecS" 19 <D.C. THREE> <D.C. THREE> <D.C. THREE>
899\& "\ecT" 20 <D.C. FOUR> <C1 29> <C1 29>
900\& "\ecU" 21 <NEG. ACK.> <C1 5> <LINE FEED> ***
901\& "\ecV" 22 <SYNCHRONOUS IDLE> <BACKSPACE> <BACKSPACE>
902\& "\ecW" 23 <E.O. TRANS. BLOCK> <C1 7> <C1 7>
903\& "\ecX" 24 <CANCEL> <CANCEL> <CANCEL>
904\& "\ecY" 25 <E.O. MEDIUM> <E.O. MEDIUM> <E.O. MEDIUM>
905\& "\ecZ" 26 <SUBSTITUTE> <C1 18> <C1 18>
906\& "\ec[" 27 <ESCAPE> <C1 15> <C1 15>
907\& "\ec\e\e" 28 <FILE SEP.>\e <FILE SEP.>\e <FILE SEP.>\e
908\& "\ec]" 29 <GROUP SEP.> <GROUP SEP.> <GROUP SEP.>
909\& "\ec^" 30 <RECORD SEP.> <RECORD SEP.> <RECORD SEP.> ***><
910\& "\ec_" 31 <UNIT SEP.> <UNIT SEP.> <UNIT SEP.> ***><
911.Ve
912.SH "FUNCTION DIFFERENCES"
913.IX Header "FUNCTION DIFFERENCES"
914.IP "\fIchr()\fR" 8
915.IX Item "chr()"
916\&\fIchr()\fR must be given an \s-1EBCDIC\s0 code number argument to yield a desired
917character return value on an \s-1EBCDIC\s0 machine. For example:
918.Sp
919.Vb 1
920\& $CAPITAL_LETTER_A = chr(193);
921.Ve
922.IP "\fIord()\fR" 8
923.IX Item "ord()"
924\&\fIord()\fR will return \s-1EBCDIC\s0 code number values on an \s-1EBCDIC\s0 machine.
925For example:
926.Sp
927.Vb 1
928\& $the_number_193 = ord("A");
929.Ve
930.IP "\fIpack()\fR" 8
931.IX Item "pack()"
932The c and C templates for \fIpack()\fR are dependent upon character set
933encoding. Examples of usage on \s-1EBCDIC\s0 include:
934.Sp
935.Vb 4
936\& $foo = pack("CCCC",193,194,195,196);
937\& # $foo eq "ABCD"
938\& $foo = pack("C4",193,194,195,196);
939\& # same thing
940.Ve
941.Sp
942.Vb 2
943\& $foo = pack("ccxxcc",193,194,195,196);
944\& # $foo eq "AB\e0\e0CD"
945.Ve
946.IP "\fIprint()\fR" 8
947.IX Item "print()"
948One must be careful with scalars and strings that are passed to
949print that contain \s-1ASCII\s0 encodings. One common place
950for this to occur is in the output of the \s-1MIME\s0 type header for
951\&\s-1CGI\s0 script writing. For example, many perl programming guides
952recommend something similar to:
953.Sp
954.Vb 2
955\& print "Content-type:\ettext/html\e015\e012\e015\e012";
956\& # this may be wrong on EBCDIC
957.Ve
958.Sp
959Under the \s-1IBM\s0 \s-1OS/390\s0 \s-1USS\s0 Web Server or WebSphere on z/OS for example
960you should instead write that as:
961.Sp
962.Vb 1
963\& print "Content-type:\ettext/html\er\en\er\en"; # OK for DGW et alia
964.Ve
965.Sp
966That is because the translation from \s-1EBCDIC\s0 to \s-1ASCII\s0 is done
967by the web server in this case (such code will not be appropriate for
968the Macintosh however). Consult your web server's documentation for
969further details.
970.IP "\fIprintf()\fR" 8
971.IX Item "printf()"
972The formats that can convert characters to numbers and vice versa
973will be different from their \s-1ASCII\s0 counterparts when executed
974on an \s-1EBCDIC\s0 machine. Examples include:
975.Sp
976.Vb 1
977\& printf("%c%c%c",193,194,195); # prints ABC
978.Ve
979.IP "\fIsort()\fR" 8
980.IX Item "sort()"
981\&\s-1EBCDIC\s0 sort results may differ from \s-1ASCII\s0 sort results especially for
982mixed case strings. This is discussed in more detail below.
983.IP "\fIsprintf()\fR" 8
984.IX Item "sprintf()"
985See the discussion of \fIprintf()\fR above. An example of the use
986of sprintf would be:
987.Sp
988.Vb 1
989\& $CAPITAL_LETTER_A = sprintf("%c",193);
990.Ve
991.IP "\fIunpack()\fR" 8
992.IX Item "unpack()"
993See the discussion of \fIpack()\fR above.
994.SH "REGULAR EXPRESSION DIFFERENCES"
995.IX Header "REGULAR EXPRESSION DIFFERENCES"
996As of perl 5.005_03 the letter range regular expression such as
997[A\-Z] and [a\-z] have been especially coded to not pick up gap
998characters. For example, characters such as o\*^ \f(CW\*(C`o WITH CIRCUMFLEX\*(C'\fR
999that lie between I and J would not be matched by the
1000regular expression range \f(CW\*(C`/[H\-K]/\*(C'\fR. This works in
1001the other direction, too, if either of the range end points is
1002explicitly numeric: \f(CW\*(C`[\ex89\-\ex91]\*(C'\fR will match \f(CW\*(C`\ex8e\*(C'\fR, even
1003though \f(CW\*(C`\ex89\*(C'\fR is \f(CW\*(C`i\*(C'\fR and \f(CW\*(C`\ex91 \*(C'\fR is \f(CW\*(C`j\*(C'\fR, and \f(CW\*(C`\ex8e\*(C'\fR
1004is a gap character from the alphabetic viewpoint.
1005.PP
1006If you do want to match the alphabet gap characters in a single octet
1007regular expression try matching the hex or octal code such
1008as \f(CW\*(C`/\e313/\*(C'\fR on \s-1EBCDIC\s0 or \f(CW\*(C`/\e364/\*(C'\fR on \s-1ASCII\s0 machines to
1009have your regular expression match \f(CW\*(C`o WITH CIRCUMFLEX\*(C'\fR.
1010.PP
1011Another construct to be wary of is the inappropriate use of hex or
1012octal constants in regular expressions. Consider the following
1013set of subs:
1014.PP
1015.Vb 4
1016\& sub is_c0 {
1017\& my $char = substr(shift,0,1);
1018\& $char =~ /[\e000-\e037]/;
1019\& }
1020.Ve
1021.PP
1022.Vb 4
1023\& sub is_print_ascii {
1024\& my $char = substr(shift,0,1);
1025\& $char =~ /[\e040-\e176]/;
1026\& }
1027.Ve
1028.PP
1029.Vb 4
1030\& sub is_delete {
1031\& my $char = substr(shift,0,1);
1032\& $char eq "\e177";
1033\& }
1034.Ve
1035.PP
1036.Vb 4
1037\& sub is_c1 {
1038\& my $char = substr(shift,0,1);
1039\& $char =~ /[\e200-\e237]/;
1040\& }
1041.Ve
1042.PP
1043.Vb 4
1044\& sub is_latin_1 {
1045\& my $char = substr(shift,0,1);
1046\& $char =~ /[\e240-\e377]/;
1047\& }
1048.Ve
1049.PP
1050The above would be adequate if the concern was only with numeric code points.
1051However, the concern may be with characters rather than code points
1052and on an \s-1EBCDIC\s0 machine it may be desirable for constructs such as
1053\&\f(CW\*(C`if (is_print_ascii("A")) {print "A is a printable character\en";}\*(C'\fR to print
1054out the expected message. One way to represent the above collection
1055of character classification subs that is capable of working across the
1056four coded character sets discussed in this document is as follows:
1057.PP
1058.Vb 12
1059\& sub Is_c0 {
1060\& my $char = substr(shift,0,1);
1061\& if (ord('^')==94) { # ascii
1062\& return $char =~ /[\e000-\e037]/;
1063\& }
1064\& if (ord('^')==176) { # 37
1065\& return $char =~ /[\e000-\e003\e067\e055-\e057\e026\e005\e045\e013-\e023\e074\e075\e062\e046\e030\e031\e077\e047\e034-\e037]/;
1066\& }
1067\& if (ord('^')==95 || ord('^')==106) { # 1047 || posix-bc
1068\& return $char =~ /[\e000-\e003\e067\e055-\e057\e026\e005\e025\e013-\e023\e074\e075\e062\e046\e030\e031\e077\e047\e034-\e037]/;
1069\& }
1070\& }
1071.Ve
1072.PP
1073.Vb 4
1074\& sub Is_print_ascii {
1075\& my $char = substr(shift,0,1);
1076\& $char =~ /[ !"\e#\e$%&'()*+,\e-.\e/0-9:;<=>?\e@A-Z[\e\e\e]^_`a-z{|}~]/;
1077\& }
1078.Ve
1079.PP
1080.Vb 9
1081\& sub Is_delete {
1082\& my $char = substr(shift,0,1);
1083\& if (ord('^')==94) { # ascii
1084\& return $char eq "\e177";
1085\& }
1086\& else { # ebcdic
1087\& return $char eq "\e007";
1088\& }
1089\& }
1090.Ve
1091.PP
1092.Vb 16
1093\& sub Is_c1 {
1094\& my $char = substr(shift,0,1);
1095\& if (ord('^')==94) { # ascii
1096\& return $char =~ /[\e200-\e237]/;
1097\& }
1098\& if (ord('^')==176) { # 37
1099\& return $char =~ /[\e040-\e044\e025\e006\e027\e050-\e054\e011\e012\e033\e060\e061\e032\e063-\e066\e010\e070-\e073\e040\e024\e076\e377]/;
1100\& }
1101\& if (ord('^')==95) { # 1047
1102\& return $char =~ /[\e040-\e045\e006\e027\e050-\e054\e011\e012\e033\e060\e061\e032\e063-\e066\e010\e070-\e073\e040\e024\e076\e377]/;
1103\& }
1104\& if (ord('^')==106) { # posix-bc
1105\& return $char =~
1106\& /[\e040-\e045\e006\e027\e050-\e054\e011\e012\e033\e060\e061\e032\e063-\e066\e010\e070-\e073\e040\e024\e076\e137]/;
1107\& }
1108\& }
1109.Ve
1110.PP
1111.Vb 18
1112\& sub Is_latin_1 {
1113\& my $char = substr(shift,0,1);
1114\& if (ord('^')==94) { # ascii
1115\& return $char =~ /[\e240-\e377]/;
1116\& }
1117\& if (ord('^')==176) { # 37
1118\& return $char =~
1119\& /[\e101\e252\e112\e261\e237\e262\e152\e265\e275\e264\e232\e212\e137\e312\e257\e274\e220\e217\e352\e372\e276\e240\e266\e263\e235\e332\e233\e213\e267\e270\e271\e253\e144\e145\e142\e146\e143\e147\e236\e150\e164\e161-\e163\e170\e165-\e167\e254\e151\e355\e356\e353\e357\e354\e277\e200\e375\e376\e373\e374\e255\e256\e131\e104\e105\e102\e106\e103\e107\e234\e110\e124\e121-\e123\e130\e125-\e127\e214\e111\e315\e316\e313\e317\e314\e341\e160\e335\e336\e333\e334\e215\e216\e337]/;
1120\& }
1121\& if (ord('^')==95) { # 1047
1122\& return $char =~
1123\& /[\e101\e252\e112\e261\e237\e262\e152\e265\e273\e264\e232\e212\e260\e312\e257\e274\e220\e217\e352\e372\e276\e240\e266\e263\e235\e332\e233\e213\e267\e270\e271\e253\e144\e145\e142\e146\e143\e147\e236\e150\e164\e161-\e163\e170\e165-\e167\e254\e151\e355\e356\e353\e357\e354\e277\e200\e375\e376\e373\e374\e272\e256\e131\e104\e105\e102\e106\e103\e107\e234\e110\e124\e121-\e123\e130\e125-\e127\e214\e111\e315\e316\e313\e317\e314\e341\e160\e335\e336\e333\e334\e215\e216\e337]/;
1124\& }
1125\& if (ord('^')==106) { # posix-bc
1126\& return $char =~
1127\& /[\e101\e252\e260\e261\e237\e262\e320\e265\e171\e264\e232\e212\e272\e312\e257\e241\e220\e217\e352\e372\e276\e240\e266\e263\e235\e332\e233\e213\e267\e270\e271\e253\e144\e145\e142\e146\e143\e147\e236\e150\e164\e161-\e163\e170\e165-\e167\e254\e151\e355\e356\e353\e357\e354\e277\e200\e340\e376\e335\e374\e255\e256\e131\e104\e105\e102\e106\e103\e107\e234\e110\e124\e121-\e123\e130\e125-\e127\e214\e111\e315\e316\e313\e317\e314\e341\e160\e300\e336\e333\e334\e215\e216\e337]/;
1128\& }
1129\& }
1130.Ve
1131.PP
1132Note however that only the \f(CW\*(C`Is_ascii_print()\*(C'\fR sub is really independent
1133of coded character set. Another way to write \f(CW\*(C`Is_latin_1()\*(C'\fR would be
1134to use the characters in the range explicitly:
1135.PP
1136.Vb 4
1137\& sub Is_latin_1 {
1138\& my $char = substr(shift,0,1);
1139