RT,下面代码出自没写过几行Perl 的吾辈之手,不过效果还不错——乱的一塌糊涂。
估计你已经明白为什么有“国际C语言混乱代码大赛”而没有“国际Perl语言混乱代码大赛”了=。=
如果不清楚brainfuck 的解释器是什么可以看看这篇文章,这是一个相同的C++ 版本 =w=
@_=@ARGV;exit if @_<1;open FILE,shift; undef$/;$_=<FILE>;s/\h|\n//g ;@_=split//;$_=$~=0;@~=();while ($_<@_){$_[$_]=~/>/&&++$~;$_ [$_]=~/</&&--$~;$_[$_]=~ /\+/&&++$~[$~];$_[$_] =~/-/?--$~[$~]:1; $_[$_]=~/\./ &&printf'%c',$~ [$~];$_[$_]=~/,/?$~ [$~]=getc:1;if($_[$_] =~/\[/){$__=1;$~[$~]?++ $_&&next:1;while($__){++$_;$_ [$_]=~/\[/?++$__:1;$_[$_]=~ /\]/&&--$__;print$_[$_ ],$_;}--$_;next;}if ($_[$_]=~/\]/){ $__=1;$~[$~]?( /\/\/\/\/\/\/\/\//,qw.enjoy brainfuck ;p.,<<___________________________ %%%%%%%%%By iSpeller%%%%%%%%%%% ___________________________ ):++$_&&next;while($__){-- $_;$_[$_]=~/\]/&&++$__; $_[$_]=~/\[/&&--$__ ;}next;}++$_;}
下面的测试代码出自ArchWiki 的Arch is the best 项目,用于输出"Arch is the best!"
++>++++++>+++++<+[>[->+<]<->++++++++++<]>>.<[-]>[-<++>] <----------------.---------------.+++++.<+++[-<++++++++++>]<. >>+.++++++++++.<<.>>+.------------.---.<<.>>---. +++.++++++++++++++.+.<<+.[-]++++++++++.
Perl 是唯一的一门在RSA 加密前后看起来一样的语言。
-- Keith Bostic