Website hosting service by Active-Venture.com
  

 Back to Index

CONVERSIONS

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 the above table, along with perl's tr/// operator is all that is needed. The data in the table are in ASCII order hence the EBCDIC columns provide easy to use ASCII to EBCDIC operations that are also easily reversed.

For example, to convert ASCII to code page 037 take the output of the second column from the output of recipe 0 (modified to add \\ characters) and use it in tr/// like so:

 
    $cp_037 = 
    '\000\001\002\003\234\011\206\177\227\215\216\013\014\015\016\017' .
    '\020\021\022\023\235\205\010\207\030\031\222\217\034\035\036\037' .
    '\200\201\202\203\204\012\027\033\210\211\212\213\214\005\006\007' .
    '\220\221\026\223\224\225\226\004\230\231\232\233\024\025\236\032' .
    '\040\240\342\344\340\341\343\345\347\361\242\056\074\050\053\174' .
    '\046\351\352\353\350\355\356\357\354\337\041\044\052\051\073\254' .
    '\055\057\302\304\300\301\303\305\307\321\246\054\045\137\076\077' .
    '\370\311\312\313\310\315\316\317\314\140\072\043\100\047\075\042' .
    '\330\141\142\143\144\145\146\147\150\151\253\273\360\375\376\261' .
    '\260\152\153\154\155\156\157\160\161\162\252\272\346\270\306\244' .
    '\265\176\163\164\165\166\167\170\171\172\241\277\320\335\336\256' .
    '\136\243\245\267\251\247\266\274\275\276\133\135\257\250\264\327' .
    '\173\101\102\103\104\105\106\107\110\111\255\364\366\362\363\365' .
    '\175\112\113\114\115\116\117\120\121\122\271\373\374\371\372\377' .
    '\134\367\123\124\125\126\127\130\131\132\262\324\326\322\323\325' .
    '\060\061\062\063\064\065\066\067\070\071\263\333\334\331\332\237' ;

    my $ebcdic_string = $ascii_string;
    eval '$ebcdic_string =~ tr/\000-\377/' . $cp_037 . '/';  

To convert from EBCDIC 037 to ASCII just reverse the order of the tr/// arguments like so:

 
    my $ascii_string = $ebcdic_string;
    eval '$ascii_string = tr/' . $cp_037 . '/\000-\377/';  

Similarly one could take the output of the third column from recipe 0 to obtain a $cp_1047 table. The fourth column of the output from recipe 0 could provide a $cp_posix_bc table suitable for transcoding as well.

iconv

XPG operability often implies the presence of an iconv utility available from the shell or from the C library. Consult your system's documentation for information on iconv.

On OS/390 or z/OS see the iconv(1) manpage. One way to invoke the iconv shell utility from within perl would be to:

 
    # OS/390 or z/OS example
    $ascii_data = `echo '$ebcdic_data'| iconv -f IBM-1047 -t ISO8859-1`  

or the inverse map:

 
    # OS/390 or z/OS example
    $ebcdic_data = `echo '$ascii_data'| iconv -f ISO8859-1 -t IBM-1047`  

For other perl based conversion options see the Convert::* modules on CPAN.

C RTL

The OS/390 and z/OS C run time libraries provide _atoe() and _etoa() functions.

 

  

 

Domain name registration - 
Register cheap domain name from $7.95 and enjoy free domain services 
 

Cheap domain name search service -
Domain name services at just
$8.95/year only
 

Register domain name -
Buy domain name registration and cheap domain transfer at low, affordable price.

© 2002-2004 Active-Venture.com Web Site Hosting Service

 

[ The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong, it usually turns out to be impossible to get at or repair.   ]

 

 
 
 

Disclaimer: This documentation is provided only for the benefits of our web hosting customers.
For authoritative source of the documentation, please refer to http://www.perldoc.com