0

I'm using Convert::IBM390 to convert EBCDIC files to ASCII files.

#!/usr/bin/perl -w

use warnings;
use Convert::IBM390 qw(:all);

open EBCDIC, "<D:/EBCDIC.txt" or die "error -> opening $!";
open ASCII, ">D:/ASCII.txt" or die "error -> opening $!";

my $text;
my $template = 'e15.0 e15 z4 I2 I2 i2 N16.0 p11.0';
binmode EBCDIC;
while (read (EBCDIC, $buffer, 67))
{
   @fields = unpackeb($template, $buffer);
   $text= join(",",@fields);
   print ASCII $text."\n";
}

close EBCDIC;
close ASCII;

I got this script in this link

I have problems when the EBCDIC data contain Little or Big Endian integers.

I had searched for unpacking those character and used N/n V/v but those things are not accepted in this module. got error as

Invalid type in unpackeb: 'N'

The EBCDIC FILE from the mainframe consists of following columns:

EBCDIC Decimal(15,0)
EBCDIC String(15)
Zoned Decimal(4)
unsigned little endian integer(2)
unsigned big endian integer(2)
signed big endian integer(2)
big endian decimal(16,0)
packed decimal(11,0)

Any suggestions ?

ikegami
  • 367,544
  • 15
  • 269
  • 518
lazy
  • 77
  • 1
  • 1
  • 7

1 Answers1

0

Do you realise that all multi-byte binary numbers must be either little- or big-endian?

I assume it's an i/I or s/S field that you want to reverse the endianness of? It doesn't appear that Convert::IBM390 will let you do that, but I'm not surprised as IBM System/360, System/370 and ESA/390 are all big-endian and you should never get any data that is little-endian. Where did your data come from?

My best suggestion is that you write a simple conversion routine that takes a 32-bit value and returns the same value with its endianness reversed. Here's a program that implements swap_endianness_32 and demonstrates its functionality.

use strict;
use warnings;

printf "%08X\n", swap_endianness_32(0x12345678);

sub swap_endianness_32 {
    unpack 'N', pack 'V', shift;
}

output

78563412
Borodin
  • 126,100
  • 9
  • 70
  • 144
  • my data file would be from mainframe system... will be having copy book based on that will update the `$template` . if i use some other value like `i / I or p/ P` it would allow but the values which got converted is not correct. – lazy Feb 25 '15 at 13:17
  • i have tried the same data with [`Convert::EBCDIC`](https://metacpan.org/pod/distribution/Convert-EBCDIC/lib/Convert/EBCDIC.pm) the file got converted but other values which are not ebcdic are still present in convertedfile – lazy Feb 25 '15 at 13:22
  • @Borodin, Some machines have byte orderings that are neither little- nor big-endian. For example, I believe there's one that stores 32-bit numbers as 3412 – ikegami Feb 25 '15 at 15:52