http://www.perlmonks.org?node_id=47485

HaB has asked for the wisdom of the Perl Monks concerning the following question:

Working on a server app that receives incoming text messages, and sends back a corresponding ACK message based on certain data contained in the incoming msg. The incoming msgs are encapsulated with a start block and an end block, which can be specified in a config file that the server reads its options from. These blocks are specified by the octal value of the ascii character. For example, the start block could be a vertical tab (\013) and the end block a serial field-separator (\034). The corresponding entry in the config file would be:

startblock=\013 endblock=\034


The config file is read in a runtime, and stored in a hash, so those 2 vals would go in as

$config{'startblock'} = "\013"; $config{'endblock'} = "\034";


Now, in order to facilitate message parsing, as soon as an incoming message is received, these chars are stripped out of the message like so:
$in_msg =~ s/$config{'startblock'}//g; $in_msg =~ s/$config{'endblock'}//g;

which works just fine. The problem shows up when I try to build the ACK message. It also needs to be encapsulated by the same two chars. I have tried all of the following:
# all in quotes $ack = "$config{'startblock'}<rest of ACK msg>$config{'endblock'}"; # encap chars outside of quotes $ack = $config{'startblock'} . "<rest of ACK>" . $config{'endblock'}; # regex $ack = "<ack msg here>"; $ack =~ s/(.*)/$config{'startblock'}\1$config{'endblock'}/;
all with the same result. The ACK message ends up using the literal '\013" instead of the v-tab. Same with the '\034'.

What gives? I can't understand why it would work perfectly in one regex, and fail in the other. I'm assuming it's some sort of regex internal thing I don't know about. Any enlightenment would be most appreciated.

-HaB


hword.