(Guessing without running the code)
$body isn't being printed twice. Notice that in the opening line, there is a quote which isn't being closed. You have to scan to the next single-quote mark to see the whole statement.
P.S., there is a much subtler way to write a self-printing program (more often called a "quine") in Perl using __DATA__. When you put __DATA__ at the end of your program, Perl's compile phase leaves the filehandle to the source code open and makes it available to the program with a filehandle named DATA. This is normally used for putting static data at the end of your source code, but you can seek this filehandle back to the beginning, read it in, and print it out just like any other file. Here's the code to demonstrate:
#!/usr/local/bin/perl use strict; use warnings; seek DATA, 0, 0; while(<DATA>) { print } __DATA__
----
: () { :|:& };:
Note: All code is untested, unless otherwise stated
In reply to Re: Self-printing program
by hardburn
in thread Self-printing program
by jpfarmer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |