timpoiko has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; open (DATA,$ARGV[0]) or die "unable to open"; print "#include <stdio.h>\n#include <stdlib.h>\n\n"; print "int main(void) {\n\tunsigned char *k = calloc(2000, 1);\n"; while (<DATA>) { s/>/\t\t++k;\n/g; s/</\t\t--k;\n/g; s/\+/\t\t++*k;\n/g; s/\-/\t\t--*k;\n/g; s/\./\t\tputchar(*k);\n/g; s/\,/\t\t*k = getchar();\n/g; s/\[/\twhile (*k) {\n/g; s/\]/\t}\n/g; print "$_"; } close DATA; print "\treturn 0;\n}\n";
I can't understand why output of s/>/\t\t++k;\n/g; and s/</\t\t--k;\n/g; is so weird, ie. missing plus and minus signs, missing tabs.
Sample bf-code:
+[----->+++<]>+.---.+++++++..+++.[--->+<]>-----.--[->++++<]>-.--------.+++.------.--------.
$ perl -v This is perl 5, version 20, subversion 2 (v5.20.2)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Weird substitution, missing output
by Anonymous Monk on May 10, 2019 at 11:47 UTC | |
by AnomalousMonk (Archbishop) on May 10, 2019 at 18:25 UTC | |
by Anonymous Monk on May 10, 2019 at 20:06 UTC | |
by timpoiko (Acolyte) on May 10, 2019 at 12:13 UTC | |
by LanX (Saint) on May 10, 2019 at 13:00 UTC | |
|
Re: Weird substitution, missing output
by LanX (Saint) on May 10, 2019 at 11:38 UTC |