in reply to Weird substitution, missing output
Suppose you have a program consisting of just >. What happens to it when you run your code:
Then run the substitution only once, on each symbol:my %sub = { ">" => "\t\t++k;\n", "+" => "\t\t++*k;\n", ... # fill as needed }
Fixing the warnings about undefined hash elements (when do they happen?) and/or constructing a regular expression that would only match brainf*ck characters is left as an exercise for the reader.s/(.)/$sub{$1}/ge
A faster, but less elegant solution would be to replace + and - first, then consider other characters which might produce their own [+-].
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Weird substitution, missing output
by AnomalousMonk (Archbishop) on May 10, 2019 at 18:25 UTC | |
by Anonymous Monk on May 10, 2019 at 20:06 UTC | |
|
Re^2: Weird substitution, missing output
by timpoiko (Acolyte) on May 10, 2019 at 12:13 UTC | |
by LanX (Saint) on May 10, 2019 at 13:00 UTC |