in reply to Re: Translating non-printable ascii
in thread Translating non-printable ascii

I was trying to save space by omitting the fact that "." is counted as a digit... so I'm missing the translation values for "0.", "1.", "2." etc etc. Sorry.

I apologize, but I'm not sure I understand what your script is doing. I need to translate the other way. I need to turn ASCII 0x80 into "00", instead of the other way around. Or maybe I'm not understanding your answer. Here's a better example of what I'm trying to accomplish

I need to turn (ascii characters in curly braces):

MO{ASCII 0x81}B{ASCII 0x8D}CAJ{ASCII 0xA3}

into:

MO01B12CAJ32

Does that explain it better?

--
perl: code of the samurai

Replies are listed 'Best First'.
Re^3: Translating non-printable ascii
by Roy Johnson (Monsignor) on Oct 04, 2004 at 17:31 UTC
    Ok, here's how I would do it the other way: Make a lookup table of the translations (since it's not straightforward base conversion):
    $_="MO\x81B\x8dCAJ\xa3"; my $start = 0x80; my %xlate = map { my $first = $_; map {(chr($start++), "$first$_")} (0..9, '.') } (0..9,'.') ; s/([\x80-\xec])/$xlate{$1}/g; print;
    The compound map builds the translation table.

    Caution: Contents may have been coded under pressure.