An interesting extension of that theorem, which makes fun use of perl's eval operator, is to build an arbitrarily complex quine with the same simple structure as outlined in the recursion theorem. The difference, though, is that the recursion theorem is based on the idea of breaking up your program into two pieces, each of which know how to print the other half. This basically involves duplicating all of your code, because you have to write it once where it executes, and once where it prints. Using eval allows you to turn that idea inside out (sort of), and divide your program into two pieces, one of which prints the other half, and itself, but doesn't execute... but the other piece can execute the first piece. That way, the majority of your code only needs to be written once.
my $program = <<'END'; # put any arbitrary code here print "my \$program = <<'END';\n${program}END\neval \$program\n"; END eval $program
(Oh, and by the way... would it help you to understand your code if you knew that 34 was the ascii character code for the quotation mark, and that %c is the printf marker for printing a character by its ascii character code? Good luck... the recursion theorem is fun stuff.)
Update: one too many newlines caused the quine to grow by an empty line with each run. sloppy.
------------ :Wq Not an editor command: Wq
In reply to Re: Self-printing program
by etcshadow
in thread Self-printing program
by jpfarmer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |