in reply to Re^6: Transform ASCII into UniCode (escape_metas)
in thread Transform ASCII into UniCode

Sorry I'm too tired now, I'll check tomorrow.

Multiple levels of escaping are often kind of brainf*ck.

> would expect the strings coming in to contain the characters to operate on, not strings that Perl can turn into the characters to operate on by evaluating them.

this escape_metas can also be used with a character class [METAS] for with multiple metas.

> The \b is tricky, as I can use it to get three different results from my three subroutines:

exactly, as I said, it depends what the intended behavior is.

FWIW

my intention was to implement a sub tri = "transliterate interpolated" which allowed to write tri($input,$left,$right) and implemented $input =~ tr/LEFT/RIGHT/ while sticking close to tr's behaviour but without breaking.

I'll try again tomorrow. after GPW. :)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^8: Transform ASCII into UniCode (escape_metas)
by LanX (Saint) on Mar 23, 2021 at 23:27 UTC
    > my intention was to implement a sub tri = "transliterate interpolated" which allowed to write tri($input,$left,$right) and implemented $input =~ tr/LEFT/RIGHT/ while sticking close to tr's behaviour but without breaking.

    That's more complicated than I thought because of the special nature of tr's arguments. :(

    double-quotes allow interpolation and escape codes, single-quotes don't

    DB<76> p "a\bc" c DB<77> p length "a\bc" 3 DB<78> p 'a\bc' a\bc DB<79> p length 'a\bc' 4 DB<80> p 'a\b' eq 'a\\b' 1

    But tr forbids interpolation while allowing escape codes

    DB<80> say '$l' =~ tr/$l/xyz/r # no interpolation xy DB<81> say "a\b" =~ tr/a\b/xyz/r # but escape codes xy

    This makes evaling tr in a predictable way far too complicated.

    Just escaping delimiters won't do, if escape codes are involved.

    I think it's wise to give it up here.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery