"both expressions evaluate to the same thing when one is placed inside quotes in perl code

No, I meant "both expressions evaluate top the same thing given the language in which they are placed (perl and bash)". It's just an irrelevant coincidence that perl and bash both understand «'\x41'» to mean the same thing.

That is the difference I was asking about.

The entire point of my post is that it wasn't the relevant difference. The difference is whether "\" is in the literal or if it's in the string that's interpolated. Literals care about "\". Interpolation, concatenation, print, join, etc, etc, etc, etc don't care about "\".

why can't I then just do: $r = "$r";

Well, if you used your way of doing things, that would be an infinite loop.

Why doesn't putting the string, which is now, "\", "x", "4", "1", inside the quotes

"\","x","4","1" is not inside the quotes. "$","r" is. '"',"\","x","4","1",'"' is Perl code. "\","x","4","1" is a different sequence of characters, and you never gave it to the parser.

So your question boils a down to why does interpolation means insert into the string ("".$r."") instead of

"".eval('"'.$r."'").""

That would make interpolation completely useless and extremely dangerous.

$r = $cgi->param('r'); # If he provides <<".system("rm -rf /").">>, $r = "You said $r"; # the user deletes the server's hard drive.
$r = $cgi->param('r'); # If he provides <<$r>>, $r = "You said $r"; # the user causes an infinite loop. # He could bring down the server in a sec.

If you want to execute Perl code, you first have to have valid Perl code ('"',"\","x","4","1",'"' instead of "\","x","4","1"), and you need to call the Perl parser explicitly (eval , require, etc).


In reply to Re^7: hex code passed from command line is interpreted literally in substitution by ikegami
in thread hex code passed from command line is interpreted literally in substitution by Allasso

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.