This code uses sprintf to generate a string which is the same as its own code. It then evals that string. It's a roundabout method of saying something along the lines of 1 while fork;.#!/usr/bin/perl $q=chr(39);$n=chr(10);$t=chr(96);$a='#!/usr/bin/perl%s$q=chr(39);$n=ch +r(10);$t=chr(96);$a=%s%s%s;$s-sprintf($a,$n,$q,$a,$q,$n);eval$s;%s';$ +s=sprintf($a,$n,$q,$a,$q,$n);eval$s;
I find it a little more exciting than the alternative and more obvious solution:
Although I find this one easier to maintain ;)#!/usr/bin/perl open(F,"<$0"); undef $/; eval <F>;
I'd like to explore this area a little more, and have some Perl that mutates itself before the eval. And find some way to not run out of pids. Update: oops, eval != fork so it won't use up pids, but hopefully you get the point. After a few levels deep in the recursion, the program gets painfully slow. Maybe mutate it to the point where it doesn't eval itself anymore after so many levels.
blokhead
In reply to Re: Self Referential Code
by blokhead
in thread Self Referential Code
by /dev/null
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |