Since the two-character literal sequence  '\v' (backslash, "v") seems to be the fly in the ointment, why not handle it as the sole exceptional case? The code is simpler, but still needs substitution replacement  /e code evaluation involving an eval and I've done no Benchmark-ing to see if it's actually faster; it always pays to be suspicious when  /e or eval are involved.

>perl -wMstrict -le "use Test::More 'no_plan'; use Test::NoWarnings; ;; my $s = join '', map qq{$_\\$_$_\\$_\\$_$_}, qw(r n b a f t v) ; my $o = join '', 'x', map qq{\\${_}y\\$_\\${_}x}, qw(0 7 10 77 100 377) ; print qq{'$s'}; print qq{'$o'}; print ''; ;; for ($s, $o) { s{ ( \\ (?: [0-7]{1,3} | [rnbaft])) | \\v } { $1 ? eval qq{qq{$1}} : qq{\013} }xmsge; } print raw_hex($s); print raw_hex($o); print ''; ;; ok $s eq qq{r\rr\r\rrn\nn\n\nnb\bb\b\bba\aa\a\aaf\ff\f\fft\tt\t\ttv\0 +13v\013\013v}; ok $o eq qq{x\000y\000\000x\007y\007\007x\010y\010\010x\077y\077\077x +\100y\100\100x\377y\377\377x}; ;; ;; sub raw_hex { return join ' ', unpack '(H2)*', $_[0]; } " 'r\rr\r\rrn\nn\n\nnb\bb\b\bba\aa\a\aaf\ff\f\fft\tt\t\ttv\vv\v\vv' 'x\0y\0\0x\7y\7\7x\10y\10\10x\77y\77\77x\100y\100\100x\377y\377\377x' 72 0d 72 0d 0d 72 6e 0a 6e 0a 0a 6e 62 08 62 08 08 62 61 07 61 07 07 6 +1 66 0c 66 0c 0c 66 74 09 74 09 09 74 76 0b 76 0b 0b 76 78 00 79 00 00 78 07 79 07 07 78 08 79 08 08 78 3f 79 3f 3f 78 40 79 4 +0 40 78 ff 79 ff ff 78 ok 1 ok 2 ok 3 - no warnings 1..3

In reply to Re: C strings, unescaping of by AnomalousMonk
in thread C strings, unescaping of 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.