|Perl Monk, Perl Meditation|
Short quinesby ambrus (Abbot)
|on Jan 11, 2008 at 17:45 UTC||Need Help??|
This node contains a couple of short non-empty non-cheating perl quines. I've had most of this collection for ages, but have apparently never posted them on perlmonks.
More precisely, a perl quine is a perl script that when run with perl without any command line arguments, it outputs precisely its source code on stdout. (If you also allow stderr instead of stdout, you can get a little shorter by changing print to warn in some of these. I'm not sure which definition is better.) Some quines are considered cheating, namely those that read their own source code from the beginning, e.g. with the famous open 0 trick. It is also considered cheating to depend on the filename of the source code, or an environment variable you have to set beforehand, or, in general, any information source that's outside the source code which you have to specifically set up; that is, the quines should just work without any special tricks on how to invoke them.
Before each quine, I list a short name for identifying it, the length of its source code in bytes, and the number of non-whitespace bytes in its source.
Note that 323b and 323e end in two newlines; 323a and 323g end in one newline; while 323c, 323d, 323f and 323h ends in a graphic character.
One of these quines (323e) is the shortest non-empty one I know, but it has the disadvantage that it only works in perl 5.6.0 or later.
323a: 44 40
323b: 35 32
323c: 44 44
323d: 50 48
$\="\47";print,print for'$\="\47";print,print for'
323e: 31 26
323f: 46 44
$\=v39;print,print for'$\=v39;print,print for'
323g: 58 57
323h: 52 52