display | more...

SelfGOL was Damian Conway's entry into the third Obfuscated Perl contest. Though it was entered one year late and was thus disqualified, that's wasn't really the point. The point is that it could have been entered into all categories at the same time! What does it do?

  • self-replicate: SelfGOL is a quine - that is it can print its own source code. Usage: SelfGOL -s
  • make other programs self-replicate: alters other perl scripts so that they return their own source code with the '-s' argument. Usage: SelfGOL <progname>
  • play Conway's Game of Life: uses perl code (its own or another program) to seed the grid and then plays the Game of Life. Usage: SelfGOL -g -x=width -y=height
  • animate short text in a marquee banner: rotates given text and prints it to the screen. Usage: SelfGOL -d="text"

All this in under 1000 characters and without using any if, unless, while, until, for, foreach, goto, next, last, redo, map or grep statements. Only Damian Conway, creater of Lingua::Romana::Perligata (Perl in Latin!) and Quantum::Superpositions (indeterminate variables!), could be insane enough to make this monstrosity. He then had to go on a speaking tour titled "Extreme Perl" to explain how the damn thing works! Here it is, for your pleasure:

#!/usr/local/bin/perl -sw 
$;=$/;seek+DATA,!++$/,!$s;$_=<DATA>;$s&&print||$g&&do{$y=($x||=20)*($y||8);sub 
i{sleep&f}sub'p{print$;x$=,join$;,$b=~/.{$x}/g}$j=$j;sub'f{pop}sub 
n{substr($b,&f%$y,3)=~tr,O,O,}sub'g{$f=&f-1;($w,$w,substr($b,&f,1),O)[n($f-$x)+ 
n($x+$f)-(substr($b,&f,1)eq+O)+n$f]||$w}$w="\40";$b=join'',@ARGV?<>:$_,$w 
x$y;$b=~s).)$&=~/\w/?O:$w)ge;substr($b,$y)=q++;$g='$i=0;$i?$b:$c=$b; 
substr+$c,$i,1,g$i;$g=~s?\d+?($&+1)%$y?e;$i-$y+1?eval$g:do{$i=-1;$b=$c;p;i 
1}';sub'e{eval$g;&e}e}||eval||die+No.$; 
__DATA__ 
if($j){{$^W=$|;*_=sub{$=+s=#([A-z])(.*)#=#$+$1#=g}} 
@s=(q[$_=sprintf+pop@s,@s],q[ 
if($j){{$^W=$|;*_=sub{$=+s=#([A-z])(.*)#=#$+$1#=g}}     #_The_Perl_Journal_# 
@s=(q[%s],q[%s])x2;%s;print"\n"x&_,$_;i$j;eval} 
])x2;$_=sprintf+pop@s,@s;print"\n"x&_,$_;i$j;eval}$/=$y;$"=",";print 
q<#!/usr/local/bin/perl -sw 
if(!$s){>.($_=<>).q<}else{@s=(q[printf+pop@s,@s],q[#!/usr/local/bin/perl -sw 
if(!$s){>.(s$%$%%$g,tr=[=[===tr=]=]=||&d,$_).q<}else{@s=(q[%s],q[%s])x2;%s} 
])x2;printf+pop@s,@s} 
>

Log in or register to write something here or to contact authors.