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

Hello I am very new to Perl and was going through the old Perl obfuscated code contests. The curse-based skiing game caught my interest. I tried running it in bash but keep getting errors every time. What am I missing to be able to run this code?
undef $/;open(_,$0);/ \dx([\dA-F]*)/while(<_>);@&=split(//,$1);@/=@&; $".=chr(hex(join("",splice(@&,0,2))))while(@&); eval$"; ($C,$_,@\)=(($a=$/[1]*4)*5+1, q| |x(0x20).q|\||.chr(32)x(0x10).q$*$. chr(0x20)x(0x10).(pack("CC",124,10)), sub{s/.\|(\s*?)(\S)./\|$1 $2/}, sub{s/\|(\s*?).(\S)/ \|$1$2 /}, sub{$2.$1.$3},sub{$tt=(3*$tt+7)%$C}, sub{$1.$3.$2}); while ($_) { select $/, undef, $/, $C/1E3; (sysread(STDIN, $k, 1), s/(.)(\*)(.)/(&{$\[(ord($k)-44&2)+2]})/e) if (select($a=chr(1),$/,$/,0)); print 0x75736520504F5349583B2024743D6E657720504F5349583A3A5465 726D96F733B24742D3E676574617474722828303D3E2A5F3D5C2423292F32 293B2024742D3E7365746C666C61672824742D3E676546C666C6167267E28 4543484F7C4543484F4B7C4943414E4F4E29293B202742D3E736574636328 5654494D452C31293B24742D3E736574617474722802C544353414E4F5729 3B24643D224352415348215C6E223B0A; ($p?(/.{70}\|$/):(/^\|/))||(&{$\[3]}<$/[0])?($p=!$p):&{$\[$p]}||die("$ +d"); (&{$\[3]}<$/[1])&&(s/ \|$/\|/); (/\|.*\*.*\|$/)||die("$d"); }

Replies are listed 'Best First'.
Re: Running an obfuscated script
by Bloodnok (Vicar) on May 15, 2014 at 13:34 UTC
    In order to know what you're missing, it would be a good idea if you let us know the nature of how the errors every time manifest themselves.

    That being said, you _are_ running the code as a perl c/w bach script, aren't you ?

    A user level that continues to overstate my experience :-))
      Thanks for the reply. These are the errors I'm getting:
      Having no space between pattern and following word is deprecated at sk +i.pl line 1. Integer overflow in hexadecimal number at ski.pl line 13. Number found where operator expected at ski.pl line 14, near "3" (Missing semicolon on previous line?) Bareword found where operator expected at ski.pl line 14, near "3B2474 +2D3E676574617474722828303D3E2A5F3D5C2423292F32293B2024742D3E" (Missing operator before B24742D3E676574617474722828303D3E2A5F3D5C +2423292F32293B2024742D3E?) Number found where operator expected at ski.pl line 15, near "B24742D3 +E676574617474722828303D3E2A5F3D5C2423292F32293B2024742D3E 365746" (Missing semicolon on previous line?) Bareword found where operator expected at ski.pl line 15, near "365746 +C666C61672824742D3E6765746C666C6167267E284543484F7C4543484F4" (Missing operator before C666C61672824742D3E6765746C666C6167267E28 +4543484F7C4543484F4?) Number found where operator expected at ski.pl line 16, near "C666C616 +72824742D3E6765746C666C6167267E284543484F7C4543484F4 7" (Missing semicolon on previous line?) Bareword found where operator expected at ski.pl line 16, near "7C4943 +414E4F4E29293B2024742D3E7365746363285654494D452C31293B24742D" (Missing operator before C4943414E4F4E29293B2024742D3E736574636328 +5654494D452C31293B24742D?) syntax error at ski.pl line 14, near "3" syntax error at ski.pl line 22, near "}" Execution of ski.pl aborted due to compilation errors.
Re: Running an obfuscated script
by no_slogan (Deacon) on May 15, 2014 at 14:42 UTC
    The hex codes have been damaged. I tried to repair them myself:
    print 0x75736520504F5349583B2024743D6E657720504F5349583A3A5465 726D696F733B24742D3E676574617474722828303D3E2A5F3D5C2423292F32 293B2024742D3E7365746C666C61672824742D3E6765746C666C6167267E28 4543484F7C4543484F4B7C4943414E4F4E29293B2024742D3E736574636328 5654494D452C31293B24742D3E7365746174747228302C544353414E4F5729 3B24643D224352415348215C6E223B0A;
    That needs to be all on one line. It only runs on perl5.8 or earlier, as it uses the old $# variable. Unfortunately, it doesn't seem to work for me.
Re: Running an obfuscated script
by Anonymous Monk on May 08, 2019 at 12:51 UTC
Re: Running an obfuscated script
by InfiniteSilence (Curate) on May 15, 2014 at 14:38 UTC

    Where did you get this code? Can you include a link?

    Looks like it is missing stuff. Even after you fix the problem with print statement (there are line endings in there...that is why it wraps so nicely) you still get errors like this:

    Use of uninitialized value $tt in multiplication (*) at monks1086134.p +l line 14, <_> chunk 1 (#3).. ... sub{$2.$1.$3},sub{$tt=(3*$tt+7)%$C},

    You see how it tries to assign $tt?

    Celebrate Intellectual Diversity

      Here is the source where I got the code: http://books.google.de/books?id=1GkMNv7PM68C&pg=PT512&lpg=PT512&dq=david+powell+perl&source=bl&ots=xAklm_Ubqq&sig=R1NGO4xKwI8nha8Exm0gOhaVny0&hl=en&sa=X&ei=D9J0U-TUHcuf7AaAvYDAAg&ved=0CDQQ6AEwBw