in reply to Re: hex code passed from command line is interpreted literally in substitution
in thread hex code passed from command line is interpreted literally in substitution

"The LHS of s/// is a regular expression, but the RHS is not. So, you can not expect them to behave the same way."

Nevertheless, RHS accepts the \xNN format if it is hardcoded in the script. It is only when it is passed from the terminal that it doesn't work. Why not? What makes it different when it is passed from the terminal?
  • Comment on Re^2: hex code passed from command line is interpreted literally in substitution

Replies are listed 'Best First'.
Re^3: hex code passed from command line is interpreted literally in substitution
by Anonymous Monk on Mar 05, 2011 at 22:56 UTC
    Why not? What makes it different when it is passed from the terminal?

    Why does interpolation happen only once? Because that is how it works

    my $stuff = "\n newline gets interpolated at compile time"; my $other = "$stuff \n gets interpolated at run time"; @ARGV = qw( $stuff $other NOINTERPOLATION ); print "$stuff\n$other\n@ARGV\n" __END__ newline gets interpolated at compile time newline gets interpolated at compile time gets interpolated at run time $stuff $other NOINTERPOLATION
    See, $stuff and $other and @ARGV all get interpolated in that print call, but the values in @ARGV won't get magically interpolated once again
Re^3: hex code passed from command line is interpreted literally in substitution
by ikegami (Patriarch) on Mar 06, 2011 at 00:54 UTC

    What makes it different when it is passed from the terminal?

    It's not different.

    $ perl -E'$_="a"; $r=$ARGV[0]; s/a/$r/; say;' '\x41' \x41 $ perl -E'$_="a"; $r="\\x41"; s/a/$r/; say;' \x41
      \\x41 is not different from \x41 ?

        Correct. Perl string literal «"\\x41"» is the same as bash string literal «'\x41'». Both produce the string "\","x","4","1". Print $r if you don't believe me.

        No. \x41 is not different from \x41, or if you're interpolating, \\x41 is not different from \\x41