Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1235 lines
54 KiB

  1. =head1 NAME
  2. perlebcdic - Considerations for running Perl on EBCDIC platforms
  3. =head1 DESCRIPTION
  4. An exploration of some of the issues facing Perl programmers
  5. on EBCDIC based computers. We do not cover localization,
  6. internationalization, or multi byte character set issues (yet).
  7. Portions that are still incomplete are marked with XXX.
  8. =head1 COMMON CHARACTER CODE SETS
  9. =head2 ASCII
  10. The American Standard Code for Information Interchange is a set of
  11. integers running from 0 to 127 (decimal) that imply character
  12. interpretation by the display and other system(s) of computers.
  13. The range 0..127 can be covered by setting the bits in a 7-bit binary
  14. digit, hence the set is sometimes referred to as a "7-bit ASCII".
  15. ASCII was described by the American National Standards Institute
  16. document ANSI X3.4-1986. It was also described by ISO 646:1991
  17. (with localization for currency symbols). The full ASCII set is
  18. given in the table below as the first 128 elements. Languages that
  19. can be written adequately with the characters in ASCII include
  20. English, Hawaiian, Indonesian, Swahili and some Native American
  21. languages.
  22. There are many character sets that extend the range of integers
  23. from 0..2**7-1 up to 2**8-1, or 8 bit bytes (octets if you prefer).
  24. One common one is the ISO 8859-1 character set.
  25. =head2 ISO 8859
  26. The ISO 8859-$n are a collection of character code sets from the
  27. International Organization for Standardization (ISO) each of which
  28. adds characters to the ASCII set that are typically found in European
  29. languages many of which are based on the Roman, or Latin, alphabet.
  30. =head2 Latin 1 (ISO 8859-1)
  31. A particular 8-bit extension to ASCII that includes grave and acute
  32. accented Latin characters. Languages that can employ ISO 8859-1
  33. include all the languages covered by ASCII as well as Afrikaans,
  34. Albanian, Basque, Catalan, Danish, Faroese, Finnish, Norwegian,
  35. Portugese, Spanish, and Swedish. Dutch is covered albeit without
  36. the ij ligature. French is covered too but without the oe ligature.
  37. German can use ISO 8859-1 but must do so without German-style
  38. quotation marks. This set is based on Western European extensions
  39. to ASCII and is commonly encountered in world wide web work.
  40. In IBM character code set identification terminology ISO 8859-1 is
  41. also known as CCSID 819 (or sometimes 0819 or even 00819).
  42. =head2 EBCDIC
  43. The Extended Binary Coded Decimal Interchange Code refers to a
  44. large collection of slightly different single and multi byte
  45. coded character sets that are different from ASCII or ISO 8859-1
  46. and typically run on host computers. The EBCDIC encodings derive
  47. from 8 bit byte extensions of Hollerith punched card encodings.
  48. The layout on the cards was such that high bits were set for the
  49. upper and lower case alphabet characters [a-z] and [A-Z], but there
  50. were gaps within each latin alphabet range.
  51. Some IBM EBCDIC character sets may be known by character code set
  52. identification numbers (CCSID numbers) or code page numbers. Leading
  53. zero digits in CCSID numbers within this document are insignificant.
  54. E.g. CCSID 0037 may be referred to as 37 in places.
  55. =head2 13 variant characters
  56. Among IBM EBCDIC character code sets there are 13 characters that
  57. are often mapped to different integer values. Those characters
  58. are known as the 13 "variant" characters and are:
  59. \ [ ] { } ^ ~ ! # | $ @ `
  60. =head2 0037
  61. Character code set ID 0037 is a mapping of the ASCII plus Latin-1
  62. characters (i.e. ISO 8859-1) to an EBCDIC set. 0037 is used
  63. in North American English locales on the OS/400 operating system
  64. that runs on AS/400 computers. CCSID 37 differs from ISO 8859-1
  65. in 237 places, in other words they agree on only 19 code point values.
  66. =head2 1047
  67. Character code set ID 1047 is also a mapping of the ASCII plus
  68. Latin-1 characters (i.e. ISO 8859-1) to an EBCDIC set. 1047 is
  69. used under Unix System Services for OS/390, and OpenEdition for VM/ESA.
  70. CCSID 1047 differs from CCSID 0037 in eight places.
  71. =head2 POSIX-BC
  72. The EBCDIC code page in use on Siemens' BS2000 system is distinct from
  73. 1047 and 0037. It is identified below as the POSIX-BC set.
  74. =head1 SINGLE OCTET TABLES
  75. The following tables list the ASCII and Latin 1 ordered sets including
  76. the subsets: C0 controls (0..31), ASCII graphics (32..7e), delete (7f),
  77. C1 controls (80..9f), and Latin-1 (a.k.a. ISO 8859-1) (a0..ff). In the
  78. table non-printing control character names as well as the Latin 1
  79. extensions to ASCII have been labelled with character names roughly
  80. corresponding to I<The Unicode Standard, Version 2.0> albeit with
  81. substitutions such as s/LATIN// and s/VULGAR// in all cases,
  82. s/CAPITAL LETTER// in some cases, and s/SMALL LETTER ([A-Z])/\l$1/
  83. in some other cases (the C<charnames> pragma names unfortunately do
  84. not list explicit names for the C0 or C1 control characters). The
  85. "names" of the C1 control set (128..159 in ISO 8859-1) listed here are
  86. somewhat arbitrary. The differences between the 0037 and 1047 sets are
  87. flagged with ***. The differences between the 1047 and POSIX-BC sets
  88. are flagged with ###. All ord() numbers listed are decimal. If you
  89. would rather see this table listing octal values then run the table
  90. (that is, the pod version of this document since this recipe may not
  91. work with a pod2_other_format translation) through:
  92. =over 4
  93. =item recipe 0
  94. =back
  95. perl -ne 'if(/(.{33})(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/)' \
  96. -e '{printf("%s%-9o%-9o%-9o%-9o\n",$1,$2,$3,$4,$5)}' perlebcdic.pod
  97. If you would rather see this table listing hexadecimal values then
  98. run the table through:
  99. =over 4
  100. =item recipe 1
  101. =back
  102. perl -ne 'if(/(.{33})(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/)' \
  103. -e '{printf("%s%-9X%-9X%-9X%-9X\n",$1,$2,$3,$4,$5)}' perlebcdic.pod
  104. 8859-1
  105. chr 0819 0037 1047 POSIX-BC
  106. ----------------------------------------------------------------
  107. <NULL> 0 0 0 0
  108. <START OF HEADING> 1 1 1 1
  109. <START OF TEXT> 2 2 2 2
  110. <END OF TEXT> 3 3 3 3
  111. <END OF TRANSMISSION> 4 55 55 55
  112. <ENQUIRY> 5 45 45 45
  113. <ACKNOWLEDGE> 6 46 46 46
  114. <BELL> 7 47 47 47
  115. <BACKSPACE> 8 22 22 22
  116. <HORIZONTAL TABULATION> 9 5 5 5
  117. <LINE FEED> 10 37 21 21 ***
  118. <VERTICAL TABULATION> 11 11 11 11
  119. <FORM FEED> 12 12 12 12
  120. <CARRIAGE RETURN> 13 13 13 13
  121. <SHIFT OUT> 14 14 14 14
  122. <SHIFT IN> 15 15 15 15
  123. <DATA LINK ESCAPE> 16 16 16 16
  124. <DEVICE CONTROL ONE> 17 17 17 17
  125. <DEVICE CONTROL TWO> 18 18 18 18
  126. <DEVICE CONTROL THREE> 19 19 19 19
  127. <DEVICE CONTROL FOUR> 20 60 60 60
  128. <NEGATIVE ACKNOWLEDGE> 21 61 61 61
  129. <SYNCHRONOUS IDLE> 22 50 50 50
  130. <END OF TRANSMISSION BLOCK> 23 38 38 38
  131. <CANCEL> 24 24 24 24
  132. <END OF MEDIUM> 25 25 25 25
  133. <SUBSTITUTE> 26 63 63 63
  134. <ESCAPE> 27 39 39 39
  135. <FILE SEPARATOR> 28 28 28 28
  136. <GROUP SEPARATOR> 29 29 29 29
  137. <RECORD SEPARATOR> 30 30 30 30
  138. <UNIT SEPARATOR> 31 31 31 31
  139. <SPACE> 32 64 64 64
  140. ! 33 90 90 90
  141. " 34 127 127 127
  142. # 35 123 123 123
  143. $ 36 91 91 91
  144. % 37 108 108 108
  145. & 38 80 80 80
  146. ' 39 125 125 125
  147. ( 40 77 77 77
  148. ) 41 93 93 93
  149. * 42 92 92 92
  150. + 43 78 78 78
  151. , 44 107 107 107
  152. - 45 96 96 96
  153. . 46 75 75 75
  154. / 47 97 97 97
  155. 0 48 240 240 240
  156. 1 49 241 241 241
  157. 2 50 242 242 242
  158. 3 51 243 243 243
  159. 4 52 244 244 244
  160. 5 53 245 245 245
  161. 6 54 246 246 246
  162. 7 55 247 247 247
  163. 8 56 248 248 248
  164. 9 57 249 249 249
  165. : 58 122 122 122
  166. ; 59 94 94 94
  167. < 60 76 76 76
  168. = 61 126 126 126
  169. > 62 110 110 110
  170. ? 63 111 111 111
  171. @ 64 124 124 124
  172. A 65 193 193 193
  173. B 66 194 194 194
  174. C 67 195 195 195
  175. D 68 196 196 196
  176. E 69 197 197 197
  177. F 70 198 198 198
  178. G 71 199 199 199
  179. H 72 200 200 200
  180. I 73 201 201 201
  181. J 74 209 209 209
  182. K 75 210 210 210
  183. L 76 211 211 211
  184. M 77 212 212 212
  185. N 78 213 213 213
  186. O 79 214 214 214
  187. P 80 215 215 215
  188. Q 81 216 216 216
  189. R 82 217 217 217
  190. S 83 226 226 226
  191. T 84 227 227 227
  192. U 85 228 228 228
  193. V 86 229 229 229
  194. W 87 230 230 230
  195. X 88 231 231 231
  196. Y 89 232 232 232
  197. Z 90 233 233 233
  198. [ 91 186 173 187 *** ###
  199. \ 92 224 224 188 ###
  200. ] 93 187 189 189 ***
  201. ^ 94 176 95 106 *** ###
  202. _ 95 109 109 109
  203. ` 96 121 121 74 ###
  204. a 97 129 129 129
  205. b 98 130 130 130
  206. c 99 131 131 131
  207. d 100 132 132 132
  208. e 101 133 133 133
  209. f 102 134 134 134
  210. g 103 135 135 135
  211. h 104 136 136 136
  212. i 105 137 137 137
  213. j 106 145 145 145
  214. k 107 146 146 146
  215. l 108 147 147 147
  216. m 109 148 148 148
  217. n 110 149 149 149
  218. o 111 150 150 150
  219. p 112 151 151 151
  220. q 113 152 152 152
  221. r 114 153 153 153
  222. s 115 162 162 162
  223. t 116 163 163 163
  224. u 117 164 164 164
  225. v 118 165 165 165
  226. w 119 166 166 166
  227. x 120 167 167 167
  228. y 121 168 168 168
  229. z 122 169 169 169
  230. { 123 192 192 251 ###
  231. | 124 79 79 79
  232. } 125 208 208 253 ###
  233. ~ 126 161 161 255 ###
  234. <DELETE> 127 7 7 7
  235. <C1 0> 128 32 32 32
  236. <C1 1> 129 33 33 33
  237. <C1 2> 130 34 34 34
  238. <C1 3> 131 35 35 35
  239. <C1 4> 132 36 36 36
  240. <C1 5> 133 21 37 37 ***
  241. <C1 6> 134 6 6 6
  242. <C1 7> 135 23 23 23
  243. <C1 8> 136 40 40 40
  244. <C1 9> 137 41 41 41
  245. <C1 10> 138 42 42 42
  246. <C1 11> 139 43 43 43
  247. <C1 12> 140 44 44 44
  248. <C1 13> 141 9 9 9
  249. <C1 14> 142 10 10 10
  250. <C1 15> 143 27 27 27
  251. <C1 16> 144 48 48 48
  252. <C1 17> 145 49 49 49
  253. <C1 18> 146 26 26 26
  254. <C1 19> 147 51 51 51
  255. <C1 20> 148 52 52 52
  256. <C1 21> 149 53 53 53
  257. <C1 22> 150 54 54 54
  258. <C1 23> 151 8 8 8
  259. <C1 24> 152 56 56 56
  260. <C1 25> 153 57 57 57
  261. <C1 26> 154 58 58 58
  262. <C1 27> 155 59 59 59
  263. <C1 28> 156 4 4 4
  264. <C1 29> 157 20 20 20
  265. <C1 30> 158 62 62 62
  266. <C1 31> 159 255 255 95 ###
  267. <NON-BREAKING SPACE> 160 65 65 65
  268. <INVERTED EXCLAMATION MARK> 161 170 170 170
  269. <CENT SIGN> 162 74 74 176 ###
  270. <POUND SIGN> 163 177 177 177
  271. <CURRENCY SIGN> 164 159 159 159
  272. <YEN SIGN> 165 178 178 178
  273. <BROKEN BAR> 166 106 106 208 ###
  274. <SECTION SIGN> 167 181 181 181
  275. <DIAERESIS> 168 189 187 121 *** ###
  276. <COPYRIGHT SIGN> 169 180 180 180
  277. <FEMININE ORDINAL INDICATOR> 170 154 154 154
  278. <LEFT POINTING GUILLEMET> 171 138 138 138
  279. <NOT SIGN> 172 95 176 186 *** ###
  280. <SOFT HYPHEN> 173 202 202 202
  281. <REGISTERED TRADE MARK SIGN> 174 175 175 175
  282. <MACRON> 175 188 188 161 ###
  283. <DEGREE SIGN> 176 144 144 144
  284. <PLUS-OR-MINUS SIGN> 177 143 143 143
  285. <SUPERSCRIPT TWO> 178 234 234 234
  286. <SUPERSCRIPT THREE> 179 250 250 250
  287. <ACUTE ACCENT> 180 190 190 190
  288. <MICRO SIGN> 181 160 160 160
  289. <PARAGRAPH SIGN> 182 182 182 182
  290. <MIDDLE DOT> 183 179 179 179
  291. <CEDILLA> 184 157 157 157
  292. <SUPERSCRIPT ONE> 185 218 218 218
  293. <MASC. ORDINAL INDICATOR> 186 155 155 155
  294. <RIGHT POINTING GUILLEMET> 187 139 139 139
  295. <FRACTION ONE QUARTER> 188 183 183 183
  296. <FRACTION ONE HALF> 189 184 184 184
  297. <FRACTION THREE QUARTERS> 190 185 185 185
  298. <INVERTED QUESTION MARK> 191 171 171 171
  299. <A WITH GRAVE> 192 100 100 100
  300. <A WITH ACUTE> 193 101 101 101
  301. <A WITH CIRCUMFLEX> 194 98 98 98
  302. <A WITH TILDE> 195 102 102 102
  303. <A WITH DIAERESIS> 196 99 99 99
  304. <A WITH RING ABOVE> 197 103 103 103
  305. <CAPITAL LIGATURE AE> 198 158 158 158
  306. <C WITH CEDILLA> 199 104 104 104
  307. <E WITH GRAVE> 200 116 116 116
  308. <E WITH ACUTE> 201 113 113 113
  309. <E WITH CIRCUMFLEX> 202 114 114 114
  310. <E WITH DIAERESIS> 203 115 115 115
  311. <I WITH GRAVE> 204 120 120 120
  312. <I WITH ACUTE> 205 117 117 117
  313. <I WITH CIRCUMFLEX> 206 118 118 118
  314. <I WITH DIAERESIS> 207 119 119 119
  315. <CAPITAL LETTER ETH> 208 172 172 172
  316. <N WITH TILDE> 209 105 105 105
  317. <O WITH GRAVE> 210 237 237 237
  318. <O WITH ACUTE> 211 238 238 238
  319. <O WITH CIRCUMFLEX> 212 235 235 235
  320. <O WITH TILDE> 213 239 239 239
  321. <O WITH DIAERESIS> 214 236 236 236
  322. <MULTIPLICATION SIGN> 215 191 191 191
  323. <O WITH STROKE> 216 128 128 128
  324. <U WITH GRAVE> 217 253 253 224 ###
  325. <U WITH ACUTE> 218 254 254 254
  326. <U WITH CIRCUMFLEX> 219 251 251 221 ###
  327. <U WITH DIAERESIS> 220 252 252 252
  328. <Y WITH ACUTE> 221 173 186 173 *** ###
  329. <CAPITAL LETTER THORN> 222 174 174 174
  330. <SMALL LETTER SHARP S> 223 89 89 89
  331. <a WITH GRAVE> 224 68 68 68
  332. <a WITH ACUTE> 225 69 69 69
  333. <a WITH CIRCUMFLEX> 226 66 66 66
  334. <a WITH TILDE> 227 70 70 70
  335. <a WITH DIAERESIS> 228 67 67 67
  336. <a WITH RING ABOVE> 229 71 71 71
  337. <SMALL LIGATURE ae> 230 156 156 156
  338. <c WITH CEDILLA> 231 72 72 72
  339. <e WITH GRAVE> 232 84 84 84
  340. <e WITH ACUTE> 233 81 81 81
  341. <e WITH CIRCUMFLEX> 234 82 82 82
  342. <e WITH DIAERESIS> 235 83 83 83
  343. <i WITH GRAVE> 236 88 88 88
  344. <i WITH ACUTE> 237 85 85 85
  345. <i WITH CIRCUMFLEX> 238 86 86 86
  346. <i WITH DIAERESIS> 239 87 87 87
  347. <SMALL LETTER eth> 240 140 140 140
  348. <n WITH TILDE> 241 73 73 73
  349. <o WITH GRAVE> 242 205 205 205
  350. <o WITH ACUTE> 243 206 206 206
  351. <o WITH CIRCUMFLEX> 244 203 203 203
  352. <o WITH TILDE> 245 207 207 207
  353. <o WITH DIAERESIS> 246 204 204 204
  354. <DIVISION SIGN> 247 225 225 225
  355. <o WITH STROKE> 248 112 112 112
  356. <u WITH GRAVE> 249 221 221 192 ###
  357. <u WITH ACUTE> 250 222 222 222
  358. <u WITH CIRCUMFLEX> 251 219 219 219
  359. <u WITH DIAERESIS> 252 220 220 220
  360. <y WITH ACUTE> 253 141 141 141
  361. <SMALL LETTER thorn> 254 142 142 142
  362. <y WITH DIAERESIS> 255 223 223 223
  363. If you would rather see the above table in CCSID 0037 order rather than
  364. ASCII + Latin-1 order then run the table through:
  365. =over 4
  366. =item recipe 2
  367. =back
  368. perl -ne 'if(/.{33}\d{1,3}\s{6,8}\d{1,3}\s{6,8}\d{1,3}\s{6,8}\d{1,3}/)'\
  369. -e '{push(@l,$_)}' \
  370. -e 'END{print map{$_->[0]}' \
  371. -e ' sort{$a->[1] <=> $b->[1]}' \
  372. -e ' map{[$_,substr($_,42,3)]}@l;}' perlebcdic.pod
  373. If you would rather see it in CCSID 1047 order then change the digit
  374. 42 in the last line to 51, like this:
  375. =over 4
  376. =item recipe 3
  377. =back
  378. perl -ne 'if(/.{33}\d{1,3}\s{6,8}\d{1,3}\s{6,8}\d{1,3}\s{6,8}\d{1,3}/)'\
  379. -e '{push(@l,$_)}' \
  380. -e 'END{print map{$_->[0]}' \
  381. -e ' sort{$a->[1] <=> $b->[1]}' \
  382. -e ' map{[$_,substr($_,51,3)]}@l;}' perlebcdic.pod
  383. If you would rather see it in POSIX-BC order then change the digit
  384. 51 in the last line to 60, like this:
  385. =over 4
  386. =item recipe 4
  387. =back
  388. perl -ne 'if(/.{33}\d{1,3}\s{6,8}\d{1,3}\s{6,8}\d{1,3}\s{6,8}\d{1,3}/)'\
  389. -e '{push(@l,$_)}' \
  390. -e 'END{print map{$_->[0]}' \
  391. -e ' sort{$a->[1] <=> $b->[1]}' \
  392. -e ' map{[$_,substr($_,60,3)]}@l;}' perlebcdic.pod
  393. =head1 IDENTIFYING CHARACTER CODE SETS
  394. To determine the character set you are running under from perl one
  395. could use the return value of ord() or chr() to test one or more
  396. character values. For example:
  397. $is_ascii = "A" eq chr(65);
  398. $is_ebcdic = "A" eq chr(193);
  399. Also, "\t" is a C<HORIZONTAL TABULATION> character so that:
  400. $is_ascii = ord("\t") == 9;
  401. $is_ebcdic = ord("\t") == 5;
  402. To distinguish EBCDIC code pages try looking at one or more of
  403. the characters that differ between them. For example:
  404. $is_ebcdic_37 = "\n" eq chr(37);
  405. $is_ebcdic_1047 = "\n" eq chr(21);
  406. Or better still choose a character that is uniquely encoded in any
  407. of the code sets, e.g.:
  408. $is_ascii = ord('[') == 91;
  409. $is_ebcdic_37 = ord('[') == 186;
  410. $is_ebcdic_1047 = ord('[') == 173;
  411. $is_ebcdic_POSIX_BC = ord('[') == 187;
  412. However, it would be unwise to write tests such as:
  413. $is_ascii = "\r" ne chr(13); # WRONG
  414. $is_ascii = "\n" ne chr(10); # ILL ADVISED
  415. Obviously the first of these will fail to distinguish most ASCII machines
  416. from either a CCSID 0037, a 1047, or a POSIX-BC EBCDIC machine since "\r" eq
  417. chr(13) under all of those coded character sets. But note too that
  418. because "\n" is chr(13) and "\r" is chr(10) on the MacIntosh (which is an
  419. ASCII machine) the second C<$is_ascii> test will lead to trouble there.
  420. To determine whether or not perl was built under an EBCDIC
  421. code page you can use the Config module like so:
  422. use Config;
  423. $is_ebcdic = $Config{'ebcdic'} eq 'define';
  424. =head1 CONVERSIONS
  425. =head2 tr///
  426. In order to convert a string of characters from one character set to
  427. another a simple list of numbers, such as in the right columns in the
  428. above table, along with perl's tr/// operator is all that is needed.
  429. The data in the table are in ASCII order hence the EBCDIC columns
  430. provide easy to use ASCII to EBCDIC operations that are also easily
  431. reversed.
  432. For example, to convert ASCII to code page 037 take the output of the second
  433. column from the output of recipe 0 (modified to add \\ characters) and use
  434. it in tr/// like so:
  435. $cp_037 =
  436. '\000\001\002\003\234\011\206\177\227\215\216\013\014\015\016\017' .
  437. '\020\021\022\023\235\205\010\207\030\031\222\217\034\035\036\037' .
  438. '\200\201\202\203\204\012\027\033\210\211\212\213\214\005\006\007' .
  439. '\220\221\026\223\224\225\226\004\230\231\232\233\024\025\236\032' .
  440. '\040\240\342\344\340\341\343\345\347\361\242\056\074\050\053\174' .
  441. '\046\351\352\353\350\355\356\357\354\337\041\044\052\051\073\254' .
  442. '\055\057\302\304\300\301\303\305\307\321\246\054\045\137\076\077' .
  443. '\370\311\312\313\310\315\316\317\314\140\072\043\100\047\075\042' .
  444. '\330\141\142\143\144\145\146\147\150\151\253\273\360\375\376\261' .
  445. '\260\152\153\154\155\156\157\160\161\162\252\272\346\270\306\244' .
  446. '\265\176\163\164\165\166\167\170\171\172\241\277\320\335\336\256' .
  447. '\136\243\245\267\251\247\266\274\275\276\133\135\257\250\264\327' .
  448. '\173\101\102\103\104\105\106\107\110\111\255\364\366\362\363\365' .
  449. '\175\112\113\114\115\116\117\120\121\122\271\373\374\371\372\377' .
  450. '\134\367\123\124\125\126\127\130\131\132\262\324\326\322\323\325' .
  451. '\060\061\062\063\064\065\066\067\070\071\263\333\334\331\332\237' ;
  452. my $ebcdic_string = $ascii_string;
  453. eval '$ebcdic_string =~ tr/\000-\377/' . $cp_037 . '/';
  454. To convert from EBCDIC 037 to ASCII just reverse the order of the tr///
  455. arguments like so:
  456. my $ascii_string = $ebcdic_string;
  457. eval '$ascii_string = tr/' . $cp_037 . '/\000-\377/';
  458. Similarly one could take the output of the third column from recipe 0 to
  459. obtain a C<$cp_1047> table. The fourth column of the output from recipe
  460. 0 could provide a C<$cp_posix_bc> table suitable for transcoding as well.
  461. =head2 iconv
  462. XPG operability often implies the presence of an I<iconv> utility
  463. available from the shell or from the C library. Consult your system's
  464. documentation for information on iconv.
  465. On OS/390 see the iconv(1) man page. One way to invoke the iconv
  466. shell utility from within perl would be to:
  467. # OS/390 example
  468. $ascii_data = `echo '$ebcdic_data'| iconv -f IBM-1047 -t ISO8859-1`
  469. or the inverse map:
  470. # OS/390 example
  471. $ebcdic_data = `echo '$ascii_data'| iconv -f ISO8859-1 -t IBM-1047`
  472. For other perl based conversion options see the Convert::* modules on CPAN.
  473. =head2 C RTL
  474. The OS/390 C run time library provides _atoe() and _etoa() functions.
  475. =head1 OPERATOR DIFFERENCES
  476. The C<..> range operator treats certain character ranges with
  477. care on EBCDIC machines. For example the following array
  478. will have twenty six elements on either an EBCDIC machine
  479. or an ASCII machine:
  480. @alphabet = ('A'..'Z'); # $#alphabet == 25
  481. The bitwise operators such as & ^ | may return different results
  482. when operating on string or character data in a perl program running
  483. on an EBCDIC machine than when run on an ASCII machine. Here is
  484. an example adapted from the one in L<perlop>:
  485. # EBCDIC-based examples
  486. print "j p \n" ^ " a h"; # prints "JAPH\n"
  487. print "JA" | " ph\n"; # prints "japh\n"
  488. print "JAPH\nJunk" & "\277\277\277\277\277"; # prints "japh\n";
  489. print 'p N$' ^ " E<H\n"; # prints "Perl\n";
  490. An interesting property of the 32 C0 control characters
  491. in the ASCII table is that they can "literally" be constructed
  492. as control characters in perl, e.g. C<(chr(0) eq "\c@")>
  493. C<(chr(1) eq "\cA")>, and so on. Perl on EBCDIC machines has been
  494. ported to take "\c@" to chr(0) and "\cA" to chr(1) as well, but the
  495. thirty three characters that result depend on which code page you are
  496. using. The table below uses the character names from the previous table
  497. but with substitutions such as s/START OF/S.O./; s/END OF /E.O./;
  498. s/TRANSMISSION/TRANS./; s/TABULATION/TAB./; s/VERTICAL/VERT./;
  499. s/HORIZONTAL/HORIZ./; s/DEVICE CONTROL/D.C./; s/SEPARATOR/SEP./;
  500. s/NEGATIVE ACKNOWLEDGE/NEG. ACK./;. The POSIX-BC and 1047 sets are
  501. identical throughout this range and differ from the 0037 set at only
  502. one spot (21 decimal). Note that the C<LINE FEED> character
  503. may be generated by "\cJ" on ASCII machines but by "\cU" on 1047 or POSIX-BC
  504. machines and cannot be generated as a C<"\c.letter."> control character on
  505. 0037 machines. Note also that "\c\\" maps to two characters
  506. not one.
  507. chr ord 8859-1 0037 1047 && POSIX-BC
  508. ------------------------------------------------------------------------
  509. "\c?" 127 <DELETE> " " ***><
  510. "\c@" 0 <NULL> <NULL> <NULL> ***><
  511. "\cA" 1 <S.O. HEADING> <S.O. HEADING> <S.O. HEADING>
  512. "\cB" 2 <S.O. TEXT> <S.O. TEXT> <S.O. TEXT>
  513. "\cC" 3 <E.O. TEXT> <E.O. TEXT> <E.O. TEXT>
  514. "\cD" 4 <E.O. TRANS.> <C1 28> <C1 28>
  515. "\cE" 5 <ENQUIRY> <HORIZ. TAB.> <HORIZ. TAB.>
  516. "\cF" 6 <ACKNOWLEDGE> <C1 6> <C1 6>
  517. "\cG" 7 <BELL> <DELETE> <DELETE>
  518. "\cH" 8 <BACKSPACE> <C1 23> <C1 23>
  519. "\cI" 9 <HORIZ. TAB.> <C1 13> <C1 13>
  520. "\cJ" 10 <LINE FEED> <C1 14> <C1 14>
  521. "\cK" 11 <VERT. TAB.> <VERT. TAB.> <VERT. TAB.>
  522. "\cL" 12 <FORM FEED> <FORM FEED> <FORM FEED>
  523. "\cM" 13 <CARRIAGE RETURN> <CARRIAGE RETURN> <CARRIAGE RETURN>
  524. "\cN" 14 <SHIFT OUT> <SHIFT OUT> <SHIFT OUT>
  525. "\cO" 15 <SHIFT IN> <SHIFT IN> <SHIFT IN>
  526. "\cP" 16 <DATA LINK ESCAPE> <DATA LINK ESCAPE> <DATA LINK ESCAPE>
  527. "\cQ" 17 <D.C. ONE> <D.C. ONE> <D.C. ONE>
  528. "\cR" 18 <D.C. TWO> <D.C. TWO> <D.C. TWO>
  529. "\cS" 19 <D.C. THREE> <D.C. THREE> <D.C. THREE>
  530. "\cT" 20 <D.C. FOUR> <C1 29> <C1 29>
  531. "\cU" 21 <NEG. ACK.> <C1 5> <LINE FEED> ***
  532. "\cV" 22 <SYNCHRONOUS IDLE> <BACKSPACE> <BACKSPACE>
  533. "\cW" 23 <E.O. TRANS. BLOCK> <C1 7> <C1 7>
  534. "\cX" 24 <CANCEL> <CANCEL> <CANCEL>
  535. "\cY" 25 <E.O. MEDIUM> <E.O. MEDIUM> <E.O. MEDIUM>
  536. "\cZ" 26 <SUBSTITUTE> <C1 18> <C1 18>
  537. "\c[" 27 <ESCAPE> <C1 15> <C1 15>
  538. "\c\\" 28 <FILE SEP.>\ <FILE SEP.>\ <FILE SEP.>\
  539. "\c]" 29 <GROUP SEP.> <GROUP SEP.> <GROUP SEP.>
  540. "\c^" 30 <RECORD SEP.> <RECORD SEP.> <RECORD SEP.> ***><
  541. "\c_" 31 <UNIT SEP.> <UNIT SEP.> <UNIT SEP.> ***><
  542. =head1 FUNCTION DIFFERENCES
  543. =over 8
  544. =item chr()
  545. chr() must be given an EBCDIC code number argument to yield a desired
  546. character return value on an EBCDIC machine. For example:
  547. $CAPITAL_LETTER_A = chr(193);
  548. =item ord()
  549. ord() will return EBCDIC code number values on an EBCDIC machine.
  550. For example:
  551. $the_number_193 = ord("A");
  552. =item pack()
  553. The c and C templates for pack() are dependent upon character set
  554. encoding. Examples of usage on EBCDIC include:
  555. $foo = pack("CCCC",193,194,195,196);
  556. # $foo eq "ABCD"
  557. $foo = pack("C4",193,194,195,196);
  558. # same thing
  559. $foo = pack("ccxxcc",193,194,195,196);
  560. # $foo eq "AB\0\0CD"
  561. =item print()
  562. One must be careful with scalars and strings that are passed to
  563. print that contain ASCII encodings. One common place
  564. for this to occur is in the output of the MIME type header for
  565. CGI script writing. For example, many perl programming guides
  566. recommend something similar to:
  567. print "Content-type:\ttext/html\015\012\015\012";
  568. # this may be wrong on EBCDIC
  569. Under the IBM OS/390 USS Web Server for example you should instead
  570. write that as:
  571. print "Content-type:\ttext/html\r\n\r\n"; # OK for DGW et alia
  572. That is because the translation from EBCDIC to ASCII is done
  573. by the web server in this case (such code will not be appropriate for
  574. the Macintosh however). Consult your web server's documentation for
  575. further details.
  576. =item printf()
  577. The formats that can convert characters to numbers and vice versa
  578. will be different from their ASCII counterparts when executed
  579. on an EBCDIC machine. Examples include:
  580. printf("%c%c%c",193,194,195); # prints ABC
  581. =item sort()
  582. EBCDIC sort results may differ from ASCII sort results especially for
  583. mixed case strings. This is discussed in more detail below.
  584. =item sprintf()
  585. See the discussion of printf() above. An example of the use
  586. of sprintf would be:
  587. $CAPITAL_LETTER_A = sprintf("%c",193);
  588. =item unpack()
  589. See the discussion of pack() above.
  590. =back
  591. =head1 REGULAR EXPRESSION DIFFERENCES
  592. As of perl 5.005_03 the letter range regular expression such as
  593. [A-Z] and [a-z] have been especially coded to not pick up gap
  594. characters. For example, characters such as E<ocirc> C<o WITH CIRCUMFLEX>
  595. that lie between I and J would not be matched by the
  596. regular expression range C</[H-K]/>.
  597. If you do want to match the alphabet gap characters in a single octet
  598. regular expression try matching the hex or octal code such
  599. as C</\313/> on EBCDIC or C</\364/> on ASCII machines to
  600. have your regular expression match C<o WITH CIRCUMFLEX>.
  601. Another construct to be wary of is the inappropriate use of hex or
  602. octal constants in regular expressions. Consider the following
  603. set of subs:
  604. sub is_c0 {
  605. my $char = substr(shift,0,1);
  606. $char =~ /[\000-\037]/;
  607. }
  608. sub is_print_ascii {
  609. my $char = substr(shift,0,1);
  610. $char =~ /[\040-\176]/;
  611. }
  612. sub is_delete {
  613. my $char = substr(shift,0,1);
  614. $char eq "\177";
  615. }
  616. sub is_c1 {
  617. my $char = substr(shift,0,1);
  618. $char =~ /[\200-\237]/;
  619. }
  620. sub is_latin_1 {
  621. my $char = substr(shift,0,1);
  622. $char =~ /[\240-\377]/;
  623. }
  624. The above would be adequate if the concern was only with numeric code points.
  625. However, the concern may be with characters rather than code points
  626. and on an EBCDIC machine it may be desirable for constructs such as
  627. C<if (is_print_ascii("A")) {print "A is a printable character\n";}> to print
  628. out the expected message. One way to represent the above collection
  629. of character classification subs that is capable of working across the
  630. four coded character sets discussed in this document is as follows:
  631. sub Is_c0 {
  632. my $char = substr(shift,0,1);
  633. if (ord('^')==94) { # ascii
  634. return $char =~ /[\000-\037]/;
  635. }
  636. if (ord('^')==176) { # 37
  637. return $char =~ /[\000-\003\067\055-\057\026\005\045\013-\023\074\075\062\046\030\031\077\047\034-\037]/;
  638. }
  639. if (ord('^')==95 || ord('^')==106) { # 1047 || posix-bc
  640. return $char =~ /[\000-\003\067\055-\057\026\005\025\013-\023\074\075\062\046\030\031\077\047\034-\037]/;
  641. }
  642. }
  643. sub Is_print_ascii {
  644. my $char = substr(shift,0,1);
  645. $char =~ /[ !"\#\$%&'()*+,\-.\/0-9:;<=>?\@A-Z[\\\]^_`a-z{|}~]/;
  646. }
  647. sub Is_delete {
  648. my $char = substr(shift,0,1);
  649. if (ord('^')==94) { # ascii
  650. return $char eq "\177";
  651. }
  652. else { # ebcdic
  653. return $char eq "\007";
  654. }
  655. }
  656. sub Is_c1 {
  657. my $char = substr(shift,0,1);
  658. if (ord('^')==94) { # ascii
  659. return $char =~ /[\200-\237]/;
  660. }
  661. if (ord('^')==176) { # 37
  662. return $char =~ /[\040-\044\025\006\027\050-\054\011\012\033\060\061\032\063-\066\010\070-\073\040\024\076\377]/;
  663. }
  664. if (ord('^')==95) { # 1047
  665. return $char =~ /[\040-\045\006\027\050-\054\011\012\033\060\061\032\063-\066\010\070-\073\040\024\076\377]/;
  666. }
  667. if (ord('^')==106) { # posix-bc
  668. return $char =~
  669. /[\040-\045\006\027\050-\054\011\012\033\060\061\032\063-\066\010\070-\073\040\024\076\137]/;
  670. }
  671. }
  672. sub Is_latin_1 {
  673. my $char = substr(shift,0,1);
  674. if (ord('^')==94) { # ascii
  675. return $char =~ /[\240-\377]/;
  676. }
  677. if (ord('^')==176) { # 37
  678. return $char =~
  679. /[\101\252\112\261\237\262\152\265\275\264\232\212\137\312\257\274\220\217\352\372\276\240\266\263\235\332\233\213\267\270\271\253\144\145\142\146\143\147\236\150\164\161-\163\170\165-\167\254\151\355\356\353\357\354\277\200\375\376\373\374\255\256\131\104\105\102\106\103\107\234\110\124\121-\123\130\125-\127\214\111\315\316\313\317\314\341\160\335\336\333\334\215\216\337]/;
  680. }
  681. if (ord('^')==95) { # 1047
  682. return $char =~
  683. /[\101\252\112\261\237\262\152\265\273\264\232\212\260\312\257\274\220\217\352\372\276\240\266\263\235\332\233\213\267\270\271\253\144\145\142\146\143\147\236\150\164\161-\163\170\165-\167\254\151\355\356\353\357\354\277\200\375\376\373\374\272\256\131\104\105\102\106\103\107\234\110\124\121-\123\130\125-\127\214\111\315\316\313\317\314\341\160\335\336\333\334\215\216\337]/;
  684. }
  685. if (ord('^')==106) { # posix-bc
  686. return $char =~
  687. /[\101\252\260\261\237\262\320\265\171\264\232\212\272\312\257\241\220\217\352\372\276\240\266\263\235\332\233\213\267\270\271\253\144\145\142\146\143\147\236\150\164\161-\163\170\165-\167\254\151\355\356\353\357\354\277\200\340\376\335\374\255\256\131\104\105\102\106\103\107\234\110\124\121-\123\130\125-\127\214\111\315\316\313\317\314\341\160\300\336\333\334\215\216\337]/;
  688. }
  689. }
  690. Note however that only the C<Is_ascii_print()> sub is really independent
  691. of coded character set. Another way to write C<Is_latin_1()> would be
  692. to use the characters in the range explicitly:
  693. sub Is_latin_1 {
  694. my $char = substr(shift,0,1);
  695. $char =~ /[������������������������������������������������������������������������������������������������]/;
  696. }
  697. Although that form may run into trouble in network transit (due to the
  698. presence of 8 bit characters) or on non ISO-Latin character sets.
  699. =head1 SOCKETS
  700. Most socket programming assumes ASCII character encodings in network
  701. byte order. Exceptions can include CGI script writing under a
  702. host web server where the server may take care of translation for you.
  703. Most host web servers convert EBCDIC data to ISO-8859-1 or Unicode on
  704. output.
  705. =head1 SORTING
  706. One big difference between ASCII based character sets and EBCDIC ones
  707. are the relative positions of upper and lower case letters and the
  708. letters compared to the digits. If sorted on an ASCII based machine the
  709. two letter abbreviation for a physician comes before the two letter
  710. for drive, that is:
  711. @sorted = sort(qw(Dr. dr.)); # @sorted holds ('Dr.','dr.') on ASCII,
  712. # but ('dr.','Dr.') on EBCDIC
  713. The property of lower case before uppercase letters in EBCDIC is
  714. even carried to the Latin 1 EBCDIC pages such as 0037 and 1047.
  715. An example would be that E<Euml> C<E WITH DIAERESIS> (203) comes
  716. before E<euml> C<e WITH DIAERESIS> (235) on an ASCII machine, but
  717. the latter (83) comes before the former (115) on an EBCDIC machine.
  718. (Astute readers will note that the upper case version of E<szlig>
  719. C<SMALL LETTER SHARP S> is simply "SS" and that the upper case version of
  720. E<yuml> C<y WITH DIAERESIS> is not in the 0..255 range but it is
  721. at U+x0178 in Unicode, or C<"\x{178}"> in a Unicode enabled Perl).
  722. The sort order will cause differences between results obtained on
  723. ASCII machines versus EBCDIC machines. What follows are some suggestions
  724. on how to deal with these differences.
  725. =head2 Ignore ASCII vs. EBCDIC sort differences.
  726. This is the least computationally expensive strategy. It may require
  727. some user education.
  728. =head2 MONO CASE then sort data.
  729. In order to minimize the expense of mono casing mixed test try to
  730. C<tr///> towards the character set case most employed within the data.
  731. If the data are primarily UPPERCASE non Latin 1 then apply tr/[a-z]/[A-Z]/
  732. then sort(). If the data are primarily lowercase non Latin 1 then
  733. apply tr/[A-Z]/[a-z]/ before sorting. If the data are primarily UPPERCASE
  734. and include Latin-1 characters then apply:
  735. tr/[a-z]/[A-Z]/;
  736. tr/[������������������������������]/[������������������������������]/;
  737. s/�/SS/g;
  738. then sort(). Do note however that such Latin-1 manipulation does not
  739. address the E<yuml> C<y WITH DIAERESIS> character that will remain at
  740. code point 255 on ASCII machines, but 223 on most EBCDIC machines
  741. where it will sort to a place less than the EBCDIC numerals. With a
  742. Unicode enabled Perl you might try:
  743. tr/^?/\x{178}/;
  744. The strategy of mono casing data before sorting does not preserve the case
  745. of the data and may not be acceptable for that reason.
  746. =head2 Convert, sort data, then re convert.
  747. This is the most expensive proposition that does not employ a network
  748. connection.
  749. =head2 Perform sorting on one type of machine only.
  750. This strategy can employ a network connection. As such
  751. it would be computationally expensive.
  752. =head1 TRANFORMATION FORMATS
  753. There are a variety of ways of transforming data with an intra character set
  754. mapping that serve a variety of purposes. Sorting was discussed in the
  755. previous section and a few of the other more popular mapping techniques are
  756. discussed next.
  757. =head2 URL decoding and encoding
  758. Note that some URLs have hexadecimal ASCII code points in them in an
  759. attempt to overcome character or protocol limitation issues. For example
  760. the tilde character is not on every keyboard hence a URL of the form:
  761. http://www.pvhp.com/~pvhp/
  762. may also be expressed as either of:
  763. http://www.pvhp.com/%7Epvhp/
  764. http://www.pvhp.com/%7epvhp/
  765. where 7E is the hexadecimal ASCII code point for '~'. Here is an example
  766. of decoding such a URL under CCSID 1047:
  767. $url = 'http://www.pvhp.com/%7Epvhp/';
  768. # this array assumes code page 1047
  769. my @a2e_1047 = (
  770. 0, 1, 2, 3, 55, 45, 46, 47, 22, 5, 21, 11, 12, 13, 14, 15,
  771. 16, 17, 18, 19, 60, 61, 50, 38, 24, 25, 63, 39, 28, 29, 30, 31,
  772. 64, 90,127,123, 91,108, 80,125, 77, 93, 92, 78,107, 96, 75, 97,
  773. 240,241,242,243,244,245,246,247,248,249,122, 94, 76,126,110,111,
  774. 124,193,194,195,196,197,198,199,200,201,209,210,211,212,213,214,
  775. 215,216,217,226,227,228,229,230,231,232,233,173,224,189, 95,109,
  776. 121,129,130,131,132,133,134,135,136,137,145,146,147,148,149,150,
  777. 151,152,153,162,163,164,165,166,167,168,169,192, 79,208,161, 7,
  778. 32, 33, 34, 35, 36, 37, 6, 23, 40, 41, 42, 43, 44, 9, 10, 27,
  779. 48, 49, 26, 51, 52, 53, 54, 8, 56, 57, 58, 59, 4, 20, 62,255,
  780. 65,170, 74,177,159,178,106,181,187,180,154,138,176,202,175,188,
  781. 144,143,234,250,190,160,182,179,157,218,155,139,183,184,185,171,
  782. 100,101, 98,102, 99,103,158,104,116,113,114,115,120,117,118,119,
  783. 172,105,237,238,235,239,236,191,128,253,254,251,252,186,174, 89,
  784. 68, 69, 66, 70, 67, 71,156, 72, 84, 81, 82, 83, 88, 85, 86, 87,
  785. 140, 73,205,206,203,207,204,225,112,221,222,219,220,141,142,223
  786. );
  787. $url =~ s/%([0-9a-fA-F]{2})/pack("c",$a2e_1047[hex($1)])/ge;
  788. Conversely, here is a partial solution for the task of encoding such
  789. a URL under the 1047 code page:
  790. $url = 'http://www.pvhp.com/~pvhp/';
  791. # this array assumes code page 1047
  792. my @e2a_1047 = (
  793. 0, 1, 2, 3,156, 9,134,127,151,141,142, 11, 12, 13, 14, 15,
  794. 16, 17, 18, 19,157, 10, 8,135, 24, 25,146,143, 28, 29, 30, 31,
  795. 128,129,130,131,132,133, 23, 27,136,137,138,139,140, 5, 6, 7,
  796. 144,145, 22,147,148,149,150, 4,152,153,154,155, 20, 21,158, 26,
  797. 32,160,226,228,224,225,227,229,231,241,162, 46, 60, 40, 43,124,
  798. 38,233,234,235,232,237,238,239,236,223, 33, 36, 42, 41, 59, 94,
  799. 45, 47,194,196,192,193,195,197,199,209,166, 44, 37, 95, 62, 63,
  800. 248,201,202,203,200,205,206,207,204, 96, 58, 35, 64, 39, 61, 34,
  801. 216, 97, 98, 99,100,101,102,103,104,105,171,187,240,253,254,177,
  802. 176,106,107,108,109,110,111,112,113,114,170,186,230,184,198,164,
  803. 181,126,115,116,117,118,119,120,121,122,161,191,208, 91,222,174,
  804. 172,163,165,183,169,167,182,188,189,190,221,168,175, 93,180,215,
  805. 123, 65, 66, 67, 68, 69, 70, 71, 72, 73,173,244,246,242,243,245,
  806. 125, 74, 75, 76, 77, 78, 79, 80, 81, 82,185,251,252,249,250,255,
  807. 92,247, 83, 84, 85, 86, 87, 88, 89, 90,178,212,214,210,211,213,
  808. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,179,219,220,217,218,159
  809. );
  810. # The following regular expression does not address the
  811. # mappings for: ('.' => '%2E', '/' => '%2F', ':' => '%3A')
  812. $url =~ s/([\t "#%&\(\),;<=>\?\@\[\\\]^`{|}~])/sprintf("%%%02X",$e2a_1047[ord($1)])/ge;
  813. where a more complete solution would split the URL into components
  814. and apply a full s/// substitution only to the appropriate parts.
  815. In the remaining examples a @e2a or @a2e array may be employed
  816. but the assignment will not be shown explicitly. For code page 1047
  817. you could use the @a2e_1047 or @e2a_1047 arrays just shown.
  818. =head2 uu encoding and decoding
  819. The C<u> template to pack() or unpack() will render EBCDIC data in EBCDIC
  820. characters equivalent to their ASCII counterparts. For example, the
  821. following will print "Yes indeed\n" on either an ASCII or EBCDIC computer:
  822. $all_byte_chrs = '';
  823. for (0..255) { $all_byte_chrs .= chr($_); }
  824. $uuencode_byte_chrs = pack('u', $all_byte_chrs);
  825. ($uu = <<' ENDOFHEREDOC') =~ s/^\s*//gm;
  826. M``$"`P0%!@<("0H+#`T.#Q`1$A,4%187&!D:&QP='A\@(2(C)"4F)R@I*BLL
  827. M+2XO,#$R,S0U-C<X.3H[/#T^/T!!0D-$149'2$E*2TQ-3D]045)35%565UA9
  828. M6EM<75Y?8&%B8V1E9F=H:6IK;&UN;W!Q<G-T=79W>'EZ>WQ]?G^`@8*#A(6&
  829. MAXB)BHN,C8Z/D)&2DY25EI>8F9J;G)V>GZ"AHJ.DI::GJ*FJJZRMKJ^PL;*S
  830. MM+6VM[BYNKN\O;Z_P,'"P\3%QL?(R<K+S,W.S]#1TM/4U=;7V-G:V]S=WM_@
  831. ?X>+CY.7FY^CIZNOL[>[O\/'R\_3U]O?X^?K[_/W^_P``
  832. ENDOFHEREDOC
  833. if ($uuencode_byte_chrs eq $uu) {
  834. print "Yes ";
  835. }
  836. $uudecode_byte_chrs = unpack('u', $uuencode_byte_chrs);
  837. if ($uudecode_byte_chrs eq $all_byte_chrs) {
  838. print "indeed\n";
  839. }
  840. Here is a very spartan uudecoder that will work on EBCDIC provided
  841. that the @e2a array is filled in appropriately:
  842. #!/usr/local/bin/perl
  843. @e2a = ( # this must be filled in
  844. );
  845. $_ = <> until ($mode,$file) = /^begin\s*(\d*)\s*(\S*)/;
  846. open(OUT, "> $file") if $file ne "";
  847. while(<>) {
  848. last if /^end/;
  849. next if /[a-z]/;
  850. next unless int(((($e2a[ord()] - 32 ) & 077) + 2) / 3) ==
  851. int(length() / 4);
  852. print OUT unpack("u", $_);
  853. }
  854. close(OUT);
  855. chmod oct($mode), $file;
  856. =head2 Quoted-Printable encoding and decoding
  857. On ASCII encoded machines it is possible to strip characters outside of
  858. the printable set using:
  859. # This QP encoder works on ASCII only
  860. $qp_string =~ s/([=\x00-\x1F\x80-\xFF])/sprintf("=%02X",ord($1))/ge;
  861. Whereas a QP encoder that works on both ASCII and EBCDIC machines
  862. would look somewhat like the following (where the EBCDIC branch @e2a
  863. array is omitted for brevity):
  864. if (ord('A') == 65) { # ASCII
  865. $delete = "\x7F"; # ASCII
  866. @e2a = (0 .. 255) # ASCII to ASCII identity map
  867. }
  868. else { # EBCDIC
  869. $delete = "\x07"; # EBCDIC
  870. @e2a = # EBCDIC to ASCII map (as shown above)
  871. }
  872. $qp_string =~
  873. s/([^ !"\#\$%&'()*+,\-.\/0-9:;<>?\@A-Z[\\\]^_`a-z{|}~$delete])/sprintf("=%02X",$e2a[ord($1)])/ge;
  874. (although in production code the substitutions might be done
  875. in the EBCDIC branch with the @e2a array and separately in the
  876. ASCII branch without the expense of the identity map).
  877. Such QP strings can be decoded with:
  878. # This QP decoder is limited to ASCII only
  879. $string =~ s/=([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge;
  880. $string =~ s/=[\n\r]+$//;
  881. Whereas a QP decoder that works on both ASCII and EBCDIC machines
  882. would look somewhat like the following (where the @a2e array is
  883. omitted for brevity):
  884. $string =~ s/=([0-9A-Fa-f][0-9A-Fa-f])/chr $a2e[hex $1]/ge;
  885. $string =~ s/=[\n\r]+$//;
  886. =head2 Caesarian cyphers
  887. The practice of shifting an alphabet one or more characters for encipherment
  888. dates back thousands of years and was explicitly detailed by Gaius Julius
  889. Caesar in his B<Gallic Wars> text. A single alphabet shift is sometimes
  890. referred to as a rotation and the shift amount is given as a number $n after
  891. the string 'rot' or "rot$n". Rot0 and rot26 would designate identity maps
  892. on the 26 letter English version of the Latin alphabet. Rot13 has the
  893. interesting property that alternate subsequent invocations are identity maps
  894. (thus rot13 is its own non-trivial inverse in the group of 26 alphabet
  895. rotations). Hence the following is a rot13 encoder and decoder that will
  896. work on ASCII and EBCDIC machines:
  897. #!/usr/local/bin/perl
  898. while(<>){
  899. tr/n-za-mN-ZA-M/a-zA-Z/;
  900. print;
  901. }
  902. In one-liner form:
  903. perl -ne 'tr/n-za-mN-ZA-M/a-zA-Z/;print'
  904. =head1 Hashing order and checksums
  905. XXX
  906. =head1 I18N AND L10N
  907. Internationalization(I18N) and localization(L10N) are supported at least
  908. in principle even on EBCDIC machines. The details are system dependent
  909. and discussed under the L<perlebcdic/OS ISSUES> section below.
  910. =head1 MULTI OCTET CHARACTER SETS
  911. Multi byte EBCDIC code pages; Unicode, UTF-8, UTF-EBCDIC, XXX.
  912. =head1 OS ISSUES
  913. There may be a few system dependent issues
  914. of concern to EBCDIC Perl programmers.
  915. =head2 OS/400
  916. The PASE environment.
  917. =over 8
  918. =item IFS access
  919. XXX.
  920. =back
  921. =head2 OS/390
  922. Perl runs under Unix Systems Services or USS.
  923. =over 8
  924. =item chcp
  925. B<chcp> is supported as a shell utility for displaying and changing
  926. one's code page. See also L<chcp>.
  927. =item dataset access
  928. For sequential data set access try:
  929. my @ds_records = `cat //DSNAME`;
  930. or:
  931. my @ds_records = `cat //'HLQ.DSNAME'`;
  932. See also the OS390::Stdio module on CPAN.
  933. =item OS/390 iconv
  934. B<iconv> is supported as both a shell utility and a C RTL routine.
  935. See also the iconv(1) and iconv(3) manual pages.
  936. =item locales
  937. On OS/390 see L<locale> for information on locales. The L10N files
  938. are in F</usr/nls/locale>. $Config{d_setlocale} is 'define' on OS/390.
  939. =back
  940. =head2 VM/ESA?
  941. XXX.
  942. =head2 POSIX-BC?
  943. XXX.
  944. =head1 BUGS
  945. This pod document contains literal Latin 1 characters and may encounter
  946. translation difficulties. In particular one popular nroff implementation
  947. was known to strip accented characters to their unaccented counterparts
  948. while attempting to view this document through the B<pod2man> program
  949. (for example, you may see a plain C<y> rather than one with a diaeresis
  950. as in E<yuml>). Another nroff truncated the resultant man page at
  951. the first occurence of 8 bit characters.
  952. Not all shells will allow multiple C<-e> string arguments to perl to
  953. be concatenated together properly as recipes 2, 3, and 4 might seem
  954. to imply.
  955. Perl does not yet work with any Unicode features on EBCDIC platforms.
  956. =head1 SEE ALSO
  957. L<perllocale>, L<perlfunc>.
  958. =head1 REFERENCES
  959. http://anubis.dkuug.dk/i18n/charmaps
  960. http://www.unicode.org/
  961. http://www.unicode.org/unicode/reports/tr16/
  962. http://www.wps.com/texts/codes/
  963. B<ASCII: American Standard Code for Information Infiltration> Tom Jennings,
  964. September 1999.
  965. B<The Unicode Standard Version 2.0> The Unicode Consortium,
  966. ISBN 0-201-48345-9, Addison Wesley Developers Press, July 1996.
  967. B<The Unicode Standard Version 3.0> The Unicode Consortium, Lisa Moore ed.,
  968. ISBN 0-201-61633-5, Addison Wesley Developers Press, February 2000.
  969. B<CDRA: IBM - Character Data Representation Architecture -
  970. Reference and Registry>, IBM SC09-2190-00, December 1996.
  971. "Demystifying Character Sets", Andrea Vine, Multilingual Computing
  972. & Technology, B<#26 Vol. 10 Issue 4>, August/September 1999;
  973. ISSN 1523-0309; Multilingual Computing Inc. Sandpoint ID, USA.
  974. B<Codes, Ciphers, and Other Cryptic and Clandestine Communication>
  975. Fred B. Wrixon, ISBN 1-57912-040-7, Black Dog & Leventhal Publishers,
  976. 1998.
  977. =head1 AUTHOR
  978. Peter Prymmer [email protected] wrote this in 1999 and 2000
  979. with CCSID 0819 and 0037 help from Chris Leach and
  980. AndrE<eacute> Pirard [email protected] as well as POSIX-BC
  981. help from Thomas Dorner [email protected].
  982. Thanks also to Vickie Cooper, Philip Newton, William Raffloer, and
  983. Joe Smith. Trademarks, registered trademarks, service marks and
  984. registered service marks used in this document are the property of
  985. their respective owners.