in reply to Re^2: Converting Mainframe EBCDIC data
in thread Converting Mainframe EBCDIC data

See substr for getting at the bytes, and then Encode for documentation about the decode function. For decoding COMP fields, I use the following:

sub decode_COMP3 { my $digits = unpack "H*", $_[0]; #warn "COMP-3: $digits\n" if $digits =~ m!^0?404040!; if( $digits =~ m!^(?:40)+(?:00|f0)*$!i ) { warn "Invalid (space) content for field detected: $digits."; $digits=~ s![4f]0!00!g; } elsif( $digits =~ /[abcdef]\d/ ) { my $old= $digits; $digits=~ s![a-f]!0!g; warn "Invalid number/misaligned content for field detected [$o +ld] -> [$digits]."; }; my $sign = chop $digits; if ($sign eq 'D' or $sign eq 'd') { $sign = '-' } elsif ($sign eq 'C' or $sign eq 'c') { $sign = '+' } elsif ($sign eq 'F' or $sign eq 'f') { $sign = ' ' } elsif ($sign =~ /^\d+$/) { $digits .= $sign; $sign = '' } else { $digits .= $sign; $sign = '?' }; "$sign$digits" };

If you have numbers with an implicit decimal point, you need to add that in afterwards.