Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Translating non-printable ascii

by samurai (Monk)
on Oct 04, 2004 at 17:10 UTC ( [id://396293]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://396293]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-19 05:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found