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

You will have to tell Perl that you want the number(s) passed on the command line interpreted as "hex code", whatever that means. Most likely, pack and unpack will do what you want.

  • Comment on Re: hex code passed from command line is interpreted literally in substitution

Replies are listed 'Best First'.
Re^2: hex code passed from command line is interpreted literally in substitution
by Allasso (Monk) on Mar 05, 2011 at 22:27 UTC
    thanks, this works:
    $var = 'a'; $arg_2 =~ s@\\x([0-9]+)@pack("H*", $1)@ge; $var =~ s@$arg_1@$arg_2@; # works now print "$var\n";
    Two things I am wondering though,

    1) why is this not needed on the search pattern?

    2) what other kinds of surprises might I expect in passing regexes on the command line?

      why is this not needed on the search pattern?

      The regex is compiled after interpolation.

      what other kinds of surprises might I expect in passing regexes on the command line?

      You just asked why there was no surprise with the regex.