in reply to reverse quotemeta?

You're asking, "how can I generally turn escape sequences into what they correspond to", right?
### updated (thanks, Abigail) ### Unicode NOT included sub expand_escapes { local $_ = shift; s{ ( \\ (?: x[A-Fa-f0-9]{0,2} # hex escape | 0[0-7]{0,3} # octal escape | c. # ctrl-escape | . # any other ) ) }{qq["$1"]}geexs; return $_; }


japhy -- Perl and Regex Hacker

Replies are listed 'Best First'.
Re: reverse quotemeta?
by Abigail (Deacon) on Jun 26, 2001 at 22:42 UTC
    Nice... but, hex escapes and octal escapes aren't fixed width. "\xA" is a newline, and octal escapes (which need a leading 0 that you have also forgotten) can have less than 3 octets as well.

    And be aware of Unicode. There will be lots more escape sequences with Unicode.

    -- Abigail

      In Perl's double quoted strings, octal escapes don't need a leading zero.

      japhy, please don't make silent updates to your node. (I'm used to update notes using bold)

      (updated)

              - tye (but my friends call me "Tye")
Re: reverse quotemeta?
by Abigail (Deacon) on Jun 26, 2001 at 23:14 UTC
    Yeah, if only things were so simple. "\0001" is one character according to your subroutine. However, Perl thinks it's two. As tye pointed out, leading 0s aren't required (but allowed). But for octets above 077 a leading 0 doesn't seem to be allowed. And for octets above 377, you will move into Unicode territory, whether you want it or not. "\400" causes Perl to think things are really messed up.

    -- Abigail