Skip to content
A kind-of quine in perl
Perl 6
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


A kind-of quine in perl, i.e. a program that outputs its own source code—in this case, as an image (as opposed to source code like traditional quines do). Created for the quine scarf competition held by @fbz on Twitter.

I call it "kind-of-quine" because reading the source code's own file (via $0 in Perl) is generally considered cheating.1 However, because I aimed to include my own hand-pixelled font and wanted to avoid external libraries for the graphics output, there simply was no space for the traditional self-quoting approach used by text-only quines, since that would have at least doubled the size of the source code.

1 Strictly speaking, an image-generating program can only ever be a true self-replicating program if the corresponding programming language would use images as source code, so we left the land of by-the-book quines already… :) You be the judge!


$ perl > quine.pbm

Voilà! You should be able to open the resulting file in GIMP or Photoshop, or convert it with ImageMagick (convert quine.pbm quine.png). The result should look like this:

The rendered quine

Technical stuff

As mentioned, the program starts by reading its own source. Then it creates a string with an empty PBM image like this:

100 1200
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

(P1 is the file format, in this case a bitmap. 100 and 1200 denote width and height, respectively, and each 0 is a pixel.)

Then, each character of the source code is plotted into this string, turning a 0 into a 1 wherever a pixel is to be set (5×8 pixels per glyph), and printed to STDOUT.

Not-so technical

Much to my delight, my entry was co-selected as a winner, and the result looks awesome! Thanks again, @fbz, and congratz to your entry, too, @kenshirriff!

You can’t perform that action at this time.