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.

In reply to Octal Weirdness by HaB

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.