📄 perlebcdic.1
字号:
Obviously the first of these will fail to distinguish most \s-1ASCII\s0 machinesfrom either a \s-1CCSID\s0 0037, a 1047, or a POSIX-BC \s-1EBCDIC\s0 machine since \*(L"\er\*(R" eq chr(13) under all of those coded character sets. But note too that because \*(L"\en\*(R" is chr(13) and \*(L"\er\*(R" is chr(10) on the MacIntosh (which is an \&\s-1ASCII\s0 machine) the second \f(CW$is_ascii\fR test will lead to trouble there..PPTo determine whether or not perl was built under an \s-1EBCDIC\s0 code page you can use the Config module like so:.PP.Vb 2\& use Config;\& $is_ebcdic = $Config{\*(Aqebcdic\*(Aq} eq \*(Aqdefine\*(Aq;.Ve.SH "CONVERSIONS".IX Header "CONVERSIONS".Sh "tr///".IX Subsection "tr///"In order to convert a string of characters from one character set to another a simple list of numbers, such as in the right columns in theabove table, along with perl's tr/// operator is all that is needed. The data in the table are in \s-1ASCII\s0 order hence the \s-1EBCDIC\s0 columns provide easy to use \s-1ASCII\s0 to \s-1EBCDIC\s0 operations that are also easily reversed..PPFor example, to convert \s-1ASCII\s0 to code page 037 take the output of the second column from the output of recipe 0 (modified to add \e\e characters) and use it in tr/// like so:.PP.Vb 10\& $cp_037 = \& \*(Aq\e000\e001\e002\e003\e234\e011\e206\e177\e227\e215\e216\e013\e014\e015\e016\e017\*(Aq .\& \*(Aq\e020\e021\e022\e023\e235\e205\e010\e207\e030\e031\e222\e217\e034\e035\e036\e037\*(Aq .\& \*(Aq\e200\e201\e202\e203\e204\e012\e027\e033\e210\e211\e212\e213\e214\e005\e006\e007\*(Aq .\& \*(Aq\e220\e221\e026\e223\e224\e225\e226\e004\e230\e231\e232\e233\e024\e025\e236\e032\*(Aq .\& \*(Aq\e040\e240\e342\e344\e340\e341\e343\e345\e347\e361\e242\e056\e074\e050\e053\e174\*(Aq .\& \*(Aq\e046\e351\e352\e353\e350\e355\e356\e357\e354\e337\e041\e044\e052\e051\e073\e254\*(Aq .\& \*(Aq\e055\e057\e302\e304\e300\e301\e303\e305\e307\e321\e246\e054\e045\e137\e076\e077\*(Aq .\& \*(Aq\e370\e311\e312\e313\e310\e315\e316\e317\e314\e140\e072\e043\e100\e047\e075\e042\*(Aq .\& \*(Aq\e330\e141\e142\e143\e144\e145\e146\e147\e150\e151\e253\e273\e360\e375\e376\e261\*(Aq .\& \*(Aq\e260\e152\e153\e154\e155\e156\e157\e160\e161\e162\e252\e272\e346\e270\e306\e244\*(Aq .\& \*(Aq\e265\e176\e163\e164\e165\e166\e167\e170\e171\e172\e241\e277\e320\e335\e336\e256\*(Aq .\& \*(Aq\e136\e243\e245\e267\e251\e247\e266\e274\e275\e276\e133\e135\e257\e250\e264\e327\*(Aq .\& \*(Aq\e173\e101\e102\e103\e104\e105\e106\e107\e110\e111\e255\e364\e366\e362\e363\e365\*(Aq .\& \*(Aq\e175\e112\e113\e114\e115\e116\e117\e120\e121\e122\e271\e373\e374\e371\e372\e377\*(Aq .\& \*(Aq\e134\e367\e123\e124\e125\e126\e127\e130\e131\e132\e262\e324\e326\e322\e323\e325\*(Aq .\& \*(Aq\e060\e061\e062\e063\e064\e065\e066\e067\e070\e071\e263\e333\e334\e331\e332\e237\*(Aq ;\&\& my $ebcdic_string = $ascii_string;\& eval \*(Aq$ebcdic_string =~ tr/\*(Aq . $cp_037 . \*(Aq/\e000\-\e377/\*(Aq;.Ve.PPTo convert from \s-1EBCDIC\s0 037 to \s-1ASCII\s0 just reverse the order of the tr/// arguments like so:.PP.Vb 2\& my $ascii_string = $ebcdic_string;\& eval \*(Aq$ascii_string =~ tr/\e000\-\e377/\*(Aq . $cp_037 . \*(Aq/\*(Aq;.Ve.PPSimilarly one could take the output of the third column from recipe 0 toobtain a \f(CW$cp_1047\fR table. The fourth column of the output from recipe0 could provide a \f(CW$cp_posix_bc\fR table suitable for transcoding as well..Sh "iconv".IX Subsection "iconv"\&\s-1XPG\s0 operability often implies the presence of an \fIiconv\fR utilityavailable from the shell or from the C library. Consult your system'sdocumentation for information on iconv..PPOn \s-1OS/390\s0 or z/OS see the \fIiconv\fR\|(1) manpage. One way to invoke the iconv shell utility from within perl would be to:.PP.Vb 2\& # OS/390 or z/OS example\& $ascii_data = \`echo \*(Aq$ebcdic_data\*(Aq| iconv \-f IBM\-1047 \-t ISO8859\-1\`.Ve.PPor the inverse map:.PP.Vb 2\& # OS/390 or z/OS example\& $ebcdic_data = \`echo \*(Aq$ascii_data\*(Aq| iconv \-f ISO8859\-1 \-t IBM\-1047\`.Ve.PPFor other perl based conversion options see the Convert::* modules on \s-1CPAN\s0..Sh "C \s-1RTL\s0".IX Subsection "C RTL"The \s-1OS/390\s0 and z/OS C run time libraries provide \fI_atoe()\fR and \fI_etoa()\fR functions..SH "OPERATOR DIFFERENCES".IX Header "OPERATOR DIFFERENCES"The \f(CW\*(C`..\*(C'\fR range operator treats certain character ranges with care on \s-1EBCDIC\s0 machines. For example the following arraywill have twenty six elements on either an \s-1EBCDIC\s0 machineor an \s-1ASCII\s0 machine:.PP.Vb 1\& @alphabet = (\*(AqA\*(Aq..\*(AqZ\*(Aq); # $#alphabet == 25.Ve.PPThe bitwise operators such as & ^ | may return different resultswhen operating on string or character data in a perl program running on an \s-1EBCDIC\s0 machine than when run on an \s-1ASCII\s0 machine. Here isan example adapted from the one in perlop:.PP.Vb 5\& # EBCDIC\-based examples\& print "j p \en" ^ " a h"; # prints "JAPH\en"\& print "JA" | " ph\en"; # prints "japh\en" \& print "JAPH\enJunk" & "\e277\e277\e277\e277\e277"; # prints "japh\en";\& print \*(Aqp N$\*(Aq ^ " E<H\en"; # prints "Perl\en";.Ve.PPAn interesting property of the 32 C0 control charactersin the \s-1ASCII\s0 table is that they can \*(L"literally\*(R" be constructedas control characters in perl, e.g. \f(CW\*(C`(chr(0) eq "\ec@")\*(C'\fR \&\f(CW\*(C`(chr(1) eq "\ecA")\*(C'\fR, and so on. Perl on \s-1EBCDIC\s0 machines has been ported to take \*(L"\ec@\*(R" to \fIchr\fR\|(0) and \*(L"\ecA\*(R" to \fIchr\fR\|(1) as well, but thethirty three characters that result depend on which code page you areusing. The table below uses the character names from the previous table but with substitutions such as s/START \s-1OF/S\s0.O./; s/END \s-1OF\s0 /E.O./; s/TRANSMISSION/TRANS./; s/TABULATION/TAB./; s/VERTICAL/VERT./; s/HORIZONTAL/HORIZ./; s/DEVICE \s-1CONTROL/D\s0.C./; s/SEPARATOR/SEP./; s/NEGATIVE \s-1ACKNOWLEDGE/NEG\s0. \s-1ACK\s0./;. The POSIX-BC and 1047 sets areidentical throughout this range and differ from the 0037 set at only one spot (21 decimal). Note that the \f(CW\*(C`LINE FEED\*(C'\fR charactermay be generated by \*(L"\ecJ\*(R" on \s-1ASCII\s0 machines but by \*(L"\ecU\*(R" on 1047 or POSIX-BC machines and cannot be generated as a \f(CW"\ec.letter."\fR control character on 0037 machines. Note also that \*(L"\ec\e\e\*(R" maps to two charactersnot one..PP.Vb 10\& chr ord 8859\-1 0037 1047 && POSIX\-BC \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\& "\ec?" 127 <DELETE> " " ***><\& "\ec@" 0 <NULL> <NULL> <NULL> ***><\& "\ecA" 1 <S.O. HEADING> <S.O. HEADING> <S.O. HEADING> \& "\ecB" 2 <S.O. TEXT> <S.O. TEXT> <S.O. TEXT>\& "\ecC" 3 <E.O. TEXT> <E.O. TEXT> <E.O. TEXT>\& "\ecD" 4 <E.O. TRANS.> <C1 28> <C1 28> \& "\ecE" 5 <ENQUIRY> <HORIZ. TAB.> <HORIZ. TAB.> \& "\ecF" 6 <ACKNOWLEDGE> <C1 6> <C1 6> \& "\ecG" 7 <BELL> <DELETE> <DELETE> \& "\ecH" 8 <BACKSPACE> <C1 23> <C1 23>\& "\ecI" 9 <HORIZ. TAB.> <C1 13> <C1 13>\& "\ecJ" 10 <LINE FEED> <C1 14> <C1 14>\& "\ecK" 11 <VERT. TAB.> <VERT. TAB.> <VERT. TAB.>\& "\ecL" 12 <FORM FEED> <FORM FEED> <FORM FEED> \& "\ecM" 13 <CARRIAGE RETURN> <CARRIAGE RETURN> <CARRIAGE RETURN> \& "\ecN" 14 <SHIFT OUT> <SHIFT OUT> <SHIFT OUT>\& "\ecO" 15 <SHIFT IN> <SHIFT IN> <SHIFT IN>\& "\ecP" 16 <DATA LINK ESCAPE> <DATA LINK ESCAPE> <DATA LINK ESCAPE> \& "\ecQ" 17 <D.C. ONE> <D.C. ONE> <D.C. ONE>\& "\ecR" 18 <D.C. TWO> <D.C. TWO> <D.C. TWO>\& "\ecS" 19 <D.C. THREE> <D.C. THREE> <D.C. THREE> \& "\ecT" 20 <D.C. FOUR> <C1 29> <C1 29> \& "\ecU" 21 <NEG. ACK.> <C1 5> <LINE FEED> ***\& "\ecV" 22 <SYNCHRONOUS IDLE> <BACKSPACE> <BACKSPACE>\& "\ecW" 23 <E.O. TRANS. BLOCK> <C1 7> <C1 7>\& "\ecX" 24 <CANCEL> <CANCEL> <CANCEL>\& "\ecY" 25 <E.O. MEDIUM> <E.O. MEDIUM> <E.O. MEDIUM>\& "\ecZ" 26 <SUBSTITUTE> <C1 18> <C1 18>\& "\ec[" 27 <ESCAPE> <C1 15> <C1 15>\& "\ec\e\e" 28 <FILE SEP.>\e <FILE SEP.>\e <FILE SEP.>\e\& "\ec]" 29 <GROUP SEP.> <GROUP SEP.> <GROUP SEP.>\& "\ec^" 30 <RECORD SEP.> <RECORD SEP.> <RECORD SEP.> ***><\& "\ec_" 31 <UNIT SEP.> <UNIT SEP.> <UNIT SEP.> ***><.Ve.SH "FUNCTION DIFFERENCES".IX Header "FUNCTION DIFFERENCES".IP "\fIchr()\fR" 8.IX Item "chr()"\&\fIchr()\fR must be given an \s-1EBCDIC\s0 code number argument to yield a desired character return value on an \s-1EBCDIC\s0 machine. For example:.Sp.Vb 1\& $CAPITAL_LETTER_A = chr(193);.Ve.IP "\fIord()\fR" 8.IX Item "ord()"\&\fIord()\fR will return \s-1EBCDIC\s0 code number values on an \s-1EBCDIC\s0 machine.For example:.Sp.Vb 1\& $the_number_193 = ord("A");.Ve.IP "\fIpack()\fR" 8.IX Item "pack()"The c and C templates for \fIpack()\fR are dependent upon character set encoding. Examples of usage on \s-1EBCDIC\s0 include:.Sp.Vb 4\& $foo = pack("CCCC",193,194,195,196);\& # $foo eq "ABCD"\& $foo = pack("C4",193,194,195,196);\& # same thing\&\& $foo = pack("ccxxcc",193,194,195,196);\& # $foo eq "AB\e0\e0CD".Ve.IP "\fIprint()\fR" 8.IX Item "print()"One must be careful with scalars and strings that are passed toprint that contain \s-1ASCII\s0 encodings. One common placefor this to occur is in the output of the \s-1MIME\s0 type header for\&\s-1CGI\s0 script writing. For example, many perl programming guides recommend something similar to:.Sp.Vb 2\& print "Content\-type:\ettext/html\e015\e012\e015\e012"; \& # this may be wrong on EBCDIC.Ve.SpUnder the \s-1IBM\s0 \s-1OS/390\s0 \s-1USS\s0 Web Server or WebSphere on z/OS for example you should instead write that as:.Sp.Vb 1\& print "Content\-type:\ettext/html\er\en\er\en"; # OK for DGW et alia.Ve.SpThat is because the translation from \s-1EBCDIC\s0 to \s-1ASCII\s0 is doneby the web server in this case (such code will not be appropriate forthe Macintosh however). Consult your web server's documentation for further details..IP "\fIprintf()\fR" 8.IX Item "printf()"The formats that can convert characters to numbers and vice versawill be different from their \s-1ASCII\s0 counterparts when executedon an \s-1EBCDIC\s0 machine. Examples include:.Sp.Vb 1\& printf("%c%c%c",193,194,195); # prints ABC.Ve.IP "\fIsort()\fR" 8.IX Item "sort()"\&\s-1EBCDIC\s0 sort results may differ from \s-1ASCII\s0 sort results especially for mixed case strings. This is discussed in more detail below..IP "\fIsprintf()\fR" 8.IX Item "sprintf()"See the discussion of \fIprintf()\fR above. An example of the useof sprintf would be:.Sp.Vb 1\& $CAPITAL_LETTER_A = sprintf("%c",193);.Ve.IP "\fIunpack()\fR" 8.IX Item "unpack()"See the discussion of \fIpack()\fR above..SH "REGULAR EXPRESSION DIFFERENCES"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -