For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > April 2006 > variable non printable character replacement









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author variable non printable character replacement
zerbitx

2006-04-11, 9:58 am

I'm writing a parser for message type that has variable (usually non-printable) delimiters. To see them easily for debugging throughout development I would like so search and replace the non-printables with printable ones. Characters 4-9 are the set of delimiters for a message, and can be set to whatever by the originator of the message. If I hardcode something like

my ($msg) = @_; # The message

$msg =~ s/\x1c/:/g;

Then it replaces just fine. I know that in this particular message that character 4 of $msg is "\x28", but trying to make the replace dynamic with something like...

my @dels = split('', substr($msg, 3, 6));

$msg =~ s/$dels[0]/:/g;

or

my $del = $dels[0];
$msg =~ s/$del/:/g;

doesn't work. I've verified with ord, that $dels[0] is 28/0x1C. What am I doing wrong?
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com