PGTS PGTS Pty. Ltd.   ACN: 007 008 568

point Site Navigation

point Other Blog Threads

  Valid HTML 4.01 Transitional

   Give Windows The Boot!
   And Say Goodbye To Viruses!


   If you own a netbook/laptop~
   Download Ubuntu Netbook!

PGTS Humble Blog

Thread: Tips/Tricks For Programming etc

Author Image Gerry Patterson. The world's most humble blogger
I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones -- Albert Einstein, 1948

Simple EBCDIC Translation

Chronogical Blog Entries:

Date: Fri, 13 Jun 2008 13:43:44 +1000

Sometimes I need to quickly translate EBCDIC to ASCII. There are several very powerful efficient CPAN packages to do this in perl. However if you are using a workstation, sometimes you need access to the system libraries to install these packages. For this reason it sometimes is not possible to install a translation package. This is especially true for Windows computers within a corporate environment. I may be developing software on my own workstation, which is crammed with every utility imaginable (and is probably running cygwin). But the final target is a minimal host with only the basic ActiveState perl install. And I would need to negotiate through various support groups in order to have my new package installed along with the perl script.

In these situations I include the following rough translation subroutine at the top of my code:
my @ebcdic_tbl = (
#   0      1      2      3      4      5      6      7      8      9      A      B      C      D      E      F
sub ebc2asc {
        my $ret = "";
        foreach my $c(split('',$_[0])) {
                $ret .= $ebcdic_tbl[ord $c];
        return $ret;

# ------------------------------------------------------------------------

It doesn't look pretty, but it works. To use it, call it as follows:

        my $ascii_string = ebc2asc($bar);

Where $bar contains the EBCDIC string.

This is actually a modified version of a C program I used to use for such translations.

Other Blog Posts In This Thread:

Copyright     2008, Gerry Patterson. All Rights Reserved.