Welcome to Perl's world of little languages!

There are many little languages inside Perl, and some little languages even have little languages inside them! Regular expressions for instance are a little language inside Perl, different semantics, different syntax, different grammar. But inside this little language, there are several other little languages. For instance, the content of [ ], doesn't follow the syntax and semantic rules of the rest of the regular expressions. Another little language inside regular expressions is the \x{ } construct. Different syntax/semantics here as well. And one of the differences is that they don't interpolate variables.

Having said that, it's still possible to do what you want, once you've evalled strings repeatedly:

#!/usr/bin/perl -w use strict; use constant DLE=>0x10; my $dle = sprintf ("%02X", DLE); my $msg = pack ("CCCCC", 0x31, 0x32, 0x10, 0x10, 0x33); # match $dle's expanded, replacement is not expanded ? $msg =~ s/(??{ eval qq!"\\x{$dle}\\x{$dle}"! })/qq!"\\x{$dle}"!/gee; printf ("%02x " x length($msg) . "\n", unpack ("C*", $msg)); __END__ 31 32 10 33

Abigail


In reply to Re: Why is variable interpolation suppressed in \x{$xxx} replacement ? by Abigail-II
in thread Why is variable interpolation suppressed in \x{$xxx} replacement ? by Anonymous Monk

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.