V
3  

del.icio.us icon Bookmark this page

Edit the sidebar

Tags
Attachments
Perl 5 Wiki
SelfGOL

Damian Conway's entry into the third Obfuscated Perl Contest was a program called SelfGOL which accomplished all four obfuscation categories simultaneously in fewer than 1000 characters.

  • Its a quine
  • Turns other programs into quines
  • Plays Conway's Game of Life
  • Animates a marquee banner

It does so without importing any modules, and without using a single if, unless, while, until, for, foreach, goto, next, last, redo, map, or grep.

And here it is...

#!/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} 
>

Thoughtstream gives a seminar on SelfGOL entitled Extreme Perl – The Horror That Is SelfGOL. They also do a half-day course entitled Perl Worst Practice which illustrates a number of software engineering principles by the negative example of SelfGOL.


 

Upload Files

Click "Browse" to find the file you want to upload. When you click "Upload file" your file will be uploaded and added to the list of attachments for this page.

Maximum file size: 50MB

 
 
 
File Name Author Date Uploaded Size

Save Page As

Enter a meaningful and distinctive title for your page.

Page Title:

Tip: You'll be able to find this page later by using the title you choose.

Page Already Exists

There is already a page named XXX. Would you like to:

Save with a different name:

Save the page with the name "XXX"

Append your text to the bottom of the existing page named: "XXX"

Upload Files

Click "Browse" to find the file you want to upload. When you click "Add file" this file will be added to the list of attachments for this page, and uploaded when you save the page.

 
 
 
Add Tags

Enter a tag and click "Add tag". The tag will be saved when you save the page.

Tag: 

Suggestions: