in reply to Pattern matching simultaneous substitution

> 4. if no D or U are present, then all s becomes

Becomes what?

If the script works correctly for the sample input, please add a sequence that produces a wrong output.

Moreover, also include the expected output for the part that the script doesn't process correctly.

General comment: Use strict and warnings. They prevent some beginner mistakes.

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

Replies are listed 'Best First'.
Re^2: Pattern matching simultaneous substitution
by Anonymous Monk on Jan 05, 2022 at 20:25 UTC
    Sorry, I missed that :)
    - if no D or U are present, then all s becomes i
    The following one was not properly converted:
    old:ssssssDDDDDDDDDDDDDDsssssssssssssDDDDDssssssssssssssssssssssssssss +ssssssssssssssDDDDDDDssssssssssssssssssssssssssssssssssssssssssssssss +sssssssssssssDDDDDDssssssssssssssssssssssssssssssssssssssssssssssssss +sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss +ssssssssssss new:OOOOOOMMMMMMMMMMMMMMIIIIIIIIIIIIIMMMMMOOOOOOOOOOOOOOOOOOOOOOOOOOOO +OOOOOOOOOOOOOOMMMMMMMIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII +IIIIIIIIIIIIIMMMMMMssssssssssssssssssssssssssssssssssssssssssssssssss +sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss +ssssssssssss
      I still don't understand the rules. If the input is
      DDssDD
      what should it become? Are the "s" prior to "D" or following a "D"?

      In the new/old example, why are the final "s" not replaced? Don't they follow a "D"?

      Please, try to be more precise.

      Also, you can easily shorten the data, 2 consecutive characters of each type would do.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
        Ok, let me try again with some examples of how data look now (old) and should look (new):
        -case 1: only 's'
        old:sssss new:iiiii

        -case 2: only 's' and 'U'
        old:sssUUss new:iiiMMoo

        -case 3: only 's' and 'D'
        old:sssDDss new:oooMMii

        -case 4: 's', 'D' and 'U' (all possible characters)
        old:sssssDDDDDDDssssUUUss new:oooooMMMMMMMiiiiMMMoo

        OR
        old:sssssUUUUUUUssssDDDss new:iiiiiMMMMMMMooooMMMii

        For some reason, the code I wrote changes many but not all cases... Not that you cannot see s+D+s+D+s+<code> sequence, or <code>s+U+s+U+s+<code>. <code>D and U alternate.