syntax error at - line 1, near ";>"
- had compilation errors.

That's odd. What I get is:

sed s/eval/print/ t.pl | perl | perl -MO=Deparse open $:, shift @ARGV; $/ = undef; $_ = <$:>; tr/+-.<>[]//cd; s/(.)/$1 /g; s[((?:<\s) {2,})]['$b-=' . length($1) / 2 . ';';]egx; s[((?:>\s) {2,})]['$b+=' . length($1) / 2 . ';';]egx; s[((?:\+\s){2,})]['$a[$b]+=' . length($1) / 2 . ';';]eg; s[((?:\-\s){2,})]['$a[$b]-=' . length($1) / 2 . ';';]eg; s/>\s /\$b++;/gx; s/<\s /\$b--;/gx; s/([+-])\s/\$a[\$b]$1$1;\n/g; s/\.\s/print chr(\$a[\$b]);/g; s/,\s /\$a[\$b]=ord(substr(<>,0,1));/gx; s/\[\s/while(\$a[\$b]){/g; s/(?<=\s)\]\s/}/g; eval $_;

This looks like a simple Brainfuck interpreter. Which makes me think one mistake is s/(?<=\s)\]\s/}/g; -- the (?<=\s) should be dropped. I first thought tr/+-.<>[]//cd; was bad too, but that I misread; +-. of course means "everything from + to .", which in ASCII means "+ , - .".

Update: The behaviour for , doesn't look right either. That should probably be done with something like

$/ = undef; $_ = <$:>; $/ = \1; [...] s/,\s /\$a[\$b]=ord(<>);/gx; [...]

The current behaviour is not, strictly speaking, a bug. You can enter complete strings by entering the EOF marker (^D or ^Z) after each character. It is needlessly complicated though.


In reply to Re^2: Eval Squared by truedfx
in thread Eval Squared by zshzn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.