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

I see. I 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.

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

# Add this to the list of cases: [ "a\b\\b" => '\\/', 'xy', "a\bxb"] # Results: not ok 22 - simulate # Failed test 'simulate' # at ./2.pl line 64. # got: 'xb' # expected: 'xb' ok 23 - cheat Replacement list is longer than search list at (eval 45) line 1. not ok 24 - use # Failed test 'use' # at ./2.pl line 66. # got: '\b' # expected: 'xb'

Switching to Test2::V0 explains the test 22:

not ok 22 - simulate # Failed test 'simulate' # at ./2.pl line 64. # +-------+----+-------+ # | GOT | OP | CHECK | # +-------+----+-------+ # | a\bxb | eq | xb | # +-------+----+-------+

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^7: Transform ASCII into UniCode (escape_metas)
by LanX (Saint) on Mar 23, 2021 at 21:06 UTC
    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

      > 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