premchai21 has asked for the wisdom of the Perl Monks concerning the following question:

Running ActiveState perl v5.6.1 on Win32/98. Have not tested on Unix yet.

I had just finished building an obfuscation using nested eval for the Obfuscation section, however when I attempted to run it, it refused to work, giving me the syntax errors:

Scalar found where operator expected at metaobfu line 3, near "]$_"
        (Missing operator before $_?)
Scalar found where operator expected at metaobfu line 4, near "]$_"
        (Missing operator before $_?)
Bareword found where operator expected at metaobfu line 4, near "s$_1$_3join
$_"
Scalar found where operator expected at metaobfu line 4, near "]$_"
        (Missing operator before $_?)
Scalar found where operator expected at metaobfu line 4, near "]$_"
        (Missing operator before $_?)
Scalar found where operator expected at metaobfu line 4, near "]$_"
        (Missing operator before $_?)
Scalar found where operator expected at metaobfu line 4, near "]$;"
        (Missing operator before $;?)
Backslash found where operator expected at metaobfu line 4, near "$;\"
        (Missing operator before \?)
Backslash found where operator expected at metaobfu line 4, near "$;\"
        (Missing operator before \?)
Scalar found where operator expected at metaobfu line 4, near "$_$_"
        (Missing operator before $_?)
Backslash found where operator expected at metaobfu line 4, near "]\"
        (Missing operator before \?)
Scalar found where operator expected at metaobfu line 4, near "$_$_"
        (Missing operator before $_?)
Number found where operator expected at metaobfu line 4, near "]1"
        (Missing operator before 1?)
Scalar found where operator expected at metaobfu line 4, near "1$_"
        (Missing operator before $_?)
syntax error at metaobfu line 3, near "{="
syntax error at metaobfu line 24, near "}"
Execution of metaobfu aborted due to compilation errors.

The code follows:

$_='';s//Z/eeeee;print; sub Z{ return <<Z; local ($),$(,$;,@_) = (qw/[ ] ( ) ' ; ,/, ' '); sprintf '%s', <<EOF; my \$z=$_[1]}\@$)$(_ \"a\$bc%e$;fg$_[0]*+i$_[3]-k.lm/0n1o2p3q4r5s6tuvw +xy$_[2]{=$_[1]$_[2] sprintf$_[4]$_[1]%s$_[1]$_[3]join$_[4]$_[1]$_[1]$_[3]$;map{substr$;\$z +,length$;\$_$_[0]+$_[4]\$_$_[3]1$_[0] } ( qw^20!! 28$_[4]setsockopt reverse 20!! 4est om 40eight, oomphasaurus-ish-li-nessmen 44 23 43 J 26bumblebees 40eight, 0000000000000000000000000000000000 23twenties-in-a-row$_[3]^$_[0]$_[3] $_[1]$;s$_[4]tr s'$_[3]$_[4]map { substr$;\$_$_[3]0,2) } ('ubbidubbi', +'$_[4]tingle',$_[4]'men$_[1]$_[3] 'r stage', 'reputation', $_[1]verse$_[1]$_[3]$_[1]rst$_[4]packet','e = + mc**2'$_[3]$_[1]symball', 'swastika', 'risc processor', 'tenable', ' log', 'can', 'lt', 'imp', 'e = 2.7182818...', 'sending...', 'tsunami', 'ocarina', 'ko', $_[1]pterodactyl$_[1]$_[3]$_[1] gone$_[1]$_[3]$_[1]etymology$_[1],$_[1 +]pens'$_[3]'erbium$_[1],'natrium', 'megadodo$_[1]$_[3]' ghastly$_[1]$_[3]'etcetera', 'nepotism', 'tb', 'y +n whoosh', 'amtrak', $_[1]e$_[0]$_[1]$_[0]$_[3]map{return\$_ unless /^$;$)a-z$({2 +}$_[0]/; scalar reverse$_[4]\$1$_[4]}$;$_[1]; $_[1],'rp','ni','ft','$;q','q/','%s',' / +x3 . \"', $_[1]%s;\"$_[3]$_[1]$_[3]$_[1]pam } $(_\$$)s\$$_[4]{$_[4]pam$_[1]$_[3] +$_[1]{$_[1]$_[0],map{ sprintf\"$;%s$_[0]*$;\\\$_**%2$_[0]+\"}( $)$_[1]-5/3$_[1]$_[3]$_[4]$_[4]$_[4]'3'$($_[3]\['11','2'\]$_[3]\['-61/ +3'$_[3]$_[1]1$_[1]$(,$)'16$_[1],$_[1]0'$($_[0],'0}1..4$_[0]',';'); EOF Z }

Is there any help to be found, or am I just loony and/or forgetful?

Replies are listed 'Best First'.
Re: Meta-meta-meta-meta-obfuscation... ...that doesn't work.
by japhy (Canon) on Jun 01, 2001 at 09:08 UTC
    Here-docs are double-quoted by default. Try:
    return <<'Z'; ... Z
    Note: this is true single-quoted context -- there is absolutely ZERO interpolation. \\ is \\ and \\\\ is \\\\, ok?

    japhy -- Perl and Regex Hacker
      Just tried it. Apparently, that was part of the problem; however, I'm still getting syntax errors after two levels of evaluation -- I tried messing around with qq rather than heredocs which might be clobbered, and I put in a print to show me the code at each stage:
      $_ = 'Z()'; foreach my $x (1..5) { print "$_\n"; <STDIN>; $_ = eval $_; die $@ if $@; } sub Z { return <<'Z'; ... Z } __END__
      gives:
      Z() local ($),$(,$;,@_) = (qw/[ ] ( ) ' ; ,/, ' '); return sprintf '%s', qq"\n my \$z=$_[1]}\@$)$(_ \"a\$bc%e$;fg$_[0]*+i$_[3]-k.lm/0n1o2p3q4r5s6tuvw +xy$_[2]{=$_[1]$_[2]\n sprintf$_[4]$_[1]%s$_[1]$_[3]join$_[4]$_[1]$_[1]$_[3]$;map{substr$;\$z +,length$;\$_$_[0]+$_[4]\$_$_[3]1$_[0] } (\n qw^20!! 28$_[4]setsockopt reverse 20!! 4est om 40eight,\n oomphasaurus-ish-li-nessmen 44 23 43 J 26bumblebees 40eight,\n 0000000000000000000000000000000000 23twenties-in-a-row$_[3]^$_[0]$_[3] +\n $_[1]$;s$_[4]tr s'$_[3]$_[4]map { substr$;\$_$_[3]0,2) } ('ubbidubbi', +'$_[4]tingle',$_[4]'men$_[1]$_[3]\n 'r stage', 'reputation', $_[1]verse$_[1]$_[3]$_[1]rst$_[4]packet','e = + mc**2'$_[3]$_[1]symball',\n 'swastika', 'risc processor', 'tenable', ' log', 'can', 'lt', 'imp',\n 'e = 2.7182818...', 'sending...', 'tsunami', 'ocarina', 'ko',\n $_[1]pterodactyl$_[1]$_[3]$_[1] gone$_[1]$_[3]$_[1]etymology$_[1],$_[1 +]pens'$_[3]'erbium$_[1],'natrium',\n 'megadodo$_[1]$_[3]' ghastly$_[1]$_[3]'etcetera', 'nepotism', 'tb', 'y +n whoosh',\n 'amtrak', $_[1]e$_[0]$_[1]$_[0]$_[3]map{return\$_ unless /^$;$)a-z$({2 +}$_[0]/; scalar\n reverse$_[4]\$1$_[4]}$;$_[1]; $_[1],'rp','ni','ft','$;q','q/','%s',' / +x3 . \"',\n $_[1]%s;\"$_[3]$_[1]$_[3]$_[1]pam } $(_\$$)s\$$_[4]{$_[4]pam$_[1]$_[3] +$_[1]{$_[1]$_[0],map{\n sprintf\"$;%s$_[0]*$;\\\$_**%s$_[0]+\"}(\n $)$_[1]-5/3$_[1]$_[3]$_[4]$_[4]$_[4]'3'$($_[3]\['11','2'\]$_[3]\['-61/ +3'$_[3]$_[1]1$_[1]$(,$)'16$_[1],$_[1]0'$($_[0],'0}1..4$_[0]',';');\n "; Scalar found where operator expected at (eval 2) line 2, near "]$_" (Missing operator before $_?) Backslash found where operator expected at (eval 2) line 2, near "]\" (Missing operator before \?) Scalar found where operator expected at (eval 2) line 3, near "]$_" (Missing operator before $_?) Bareword found where operator expected at (eval 2) line 3, near "s$_[1 +]$_[3]join $_" Scalar found where operator expected at (eval 2) line 3, near "]$_" (Missing operator before $_?) Scalar found where operator expected at (eval 2) line 3, near "]$_" (Missing operator before $_?) Scalar found where operator expected at (eval 2) line 3, near "]$_" (Missing operator before $_?) Scalar found where operator expected at (eval 2) line 3, near "]$;" (Missing operator before $;?) Backslash found where operator expected at (eval 2) line 3, near "$;\" (Missing operator before \?) Backslash found where operator expected at (eval 2) line 3, near "$;\" (Missing operator before \?) Scalar found where operator expected at (eval 2) line 3, near "$_$_" (Missing operator before $_?) Backslash found where operator expected at (eval 2) line 3, near "]\" (Missing operator before \?) Scalar found where operator expected at (eval 2) line 3, near "$_$_" (Missing operator before $_?) Number found where operator expected at (eval 2) line 3, near "]1" (Missing operator before 1?) Scalar found where operator expected at (eval 2) line 3, near "1$_" (Missing operator before $_?) syntax error at (eval 2) line 2, near "{="
      But it helped. Thanks.