
perl program that outputs itself
Quote:
> hi,
> here is a little perl program i wrote that outputs its own source
> code.
> i gave this as an exercise to my pupils but nobody solved the problem.
> hope you find it funny:
> ---- autograph.pl -----
> $a='print chr(36).chr(97).chr(61).chr(39)
> .$a.chr(39).chr(59).chr(10).$a;';
> print chr(36).chr(97).chr(61).chr(39)
> .$a.chr(39).chr(59).chr(10).$a;
> --------------------------
> joachim
> ps: maybe we should create a new programming paradigm:
> in "autographic programming", every program/module/class must be able
> to output its own source code on request :-)
A program that outputs itself is called a quine.
A note to those others who've lready posted followups: Reading your own
source code to print it is considered cheating, so those aren't valid
quines [autograph.pl above is a valid quine, though]. The following
[assuming it works, it's untested] is technically a cheat.
Can any of you see how this is supposed to work? :)
You can see a bunch real quines and some cheats at:
http://www.nyx.net/~gthompso/self_perl.txt
Here's a couple of quines from the Fun With Perl mailing list:
by Kevin Reid:
xqvkliwCi0vsolfh+Ci0vkliw,>vsolfhCi07;030rug+%_q%,>
v2+u_+-B,+_g/,+_,,2'41+'5/4,1'62jh>hydo*~*1u1u+7,>
QRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz|~
NOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz
Quote:
};eval
by Pete Sergeant [in response to the one above]:
($_='Yw_xUabcdtefgdijktljkotiersjkUzxT
yvlkbfdtcierstajogvPruntRshackRJelov')
=~y/RTUv;wxYz$/ ~'\/;$=();/;eval;print
--
Klein bottle for rent - inquire within.