regular expression using ASCII symbols in PERL replace string

Forgive this question from a newbie, but is it possible to use non-printing ASCII chars in a PERL replace string, with an escape sequence like you can in the search string e.g. \x0D \x0A etc

If not how would one achieve this? \r \n etc is not sufficient here.

Also is it possible to include Unicode chars as escape sequences in the replace string?

Thanks all
dhowes_UKAsked:
Who is Participating?
 
ozoCommented:
Yes, it is possible to use the same escape characters in the replace string like you can in the search string, or any interpolating string.
0
 
ps15Commented:
these work:

Unicode like: \x{3078}
ASCII like: \x40

so you could do things like:
s/\x40/ AT /;
s/\x{3078}/ some chinese thing /;
0
 
tone28Commented:
Yeah, you can use the escape characters. Just put then in quotes

print "\x41"; # prints the character A



0
 
ozoCommented:
perldoc perlop
...
       Quote and Quote-like Operators

       While we usually think of quotes as literal values, in Perl they func-
       tion as operators, providing various kinds of interpolating and pattern
       matching capabilities.  Perl provides customary quote characters for
       these behaviors, but also provides a way for you to choose your quote
       character for any of them.  In the following table, a "{}" represents
       any pair of delimiters you choose.

           Customary  Generic        Meaning        Interpolates
               ''       q{}          Literal             no
               ""      qq{}          Literal             yes
               ``      qx{}          Command             yes*
                       qw{}         Word list            no
               //       m{}       Pattern match          yes*
                       qr{}          Pattern             yes*
                        s{}{}      Substitution          yes*
                       tr{}{}    Transliteration         no (but see below)
               <<EOF                 here-doc            yes*

               * unless the delimiter is ''.
...
       The following escape sequences are available in constructs that inter-
       polate and in transliterations.

           \t          tab             (HT, TAB)
           \n          newline         (NL)
           \r          return          (CR)
           \f          form feed       (FF)
           \b          backspace       (BS)
           \a          alarm (bell)    (BEL)
           \e          escape          (ESC)
           \033        octal char      (ESC)
           \x1b        hex char        (ESC)
           \x{263a}    wide hex char   (SMILEY)
           \c[         control char    (ESC)
           \N{name}    named Unicode character

       The following escape sequences are available in constructs that inter-
       polate but not in transliterations.

           \l          lowercase next char
           \u          uppercase next char
           \L          lowercase till \E
           \U          uppercase till \E
           \E          end case modification
           \Q          quote non-word characters till \E

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.