Re: hex to ebcdic



Gunnar Hjalmarsson schreef:

use Encode 'decode';
$hex = 'f1f2d7d9f0';
( $ebcdic = $hex ) =~ s/(..)/chr(hex $1)/eg;
$ascii = decode 'posix-bc', $ebcdic;

Ah, "posic-bc", brings back memories. I would've thought that "EBCDIC"
or "EBCDIC-US" (see `iconv -l`) would work too, but they don't, see
`perldoc Encode::Supported`.

Variant using pack()

$ perl -Mstrict -MEncode=decode -wle'
my $ebcdic = pack q/H*/, $ARGV[0];
my $ascii = decode q/posix-bc/, $ebcdic;
print $ascii;
' f1f2d7d9f0
12PR0

--
Affijn, Ruud

"Gewoon is een tijger."

.



Relevant Pages

  • Re: best method to perform operations on word lists
    ... because the regex matches the empty string as well. ... "Gewoon is een tijger." ...
    (comp.lang.perl.misc)
  • Re: string matching doesnt work
    ... @c = qw(abc de fghi); ... "Gewoon is een tijger." ... I used Mirco Wahab's solution and it worked for some of the cases but ...
    (comp.lang.perl.misc)
  • Re: Adding hashes
    ... Your 'apples pears' communicated the opposite. ... "Gewoon is een tijger." ...
    (comp.lang.perl.misc)
  • Re: Perl - Joining of Binary values
    ... "Gewoon is een tijger." ... To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx ... For additional commands, e-mail: beginners-help@xxxxxxxx ...
    (perl.beginners)
  • Perl and binary data
    ... I have a binary file I need to convert to ascii. ... have read perldoc about the pack and unpack function, ...
    (perl.beginners)