http://www.perlmonks.org?node_id=62528


in reply to Quine Whine

Hmmm...people don't seem to be interested in making them. Ah well. Here is a quine that shows a standard form that you can usually get to work...
# This is a quine. $c = "# This is a quine. "; $t = q(-c$c = "-c"; $t = q(-t); # Note the repeated text here. This appears both in data # and in source. Anything you want can go here as long # as it repeats and you do not interfere with these actions... # Substitute the variables back into the data. If you do # not like symbolic refs, you could use a hash instead, same # diff. This substitution builds source out of data. $t =~ s/-(\w+)/${$1}/g; # Since data is now source, just print it and we are done. print $t; ); # Note the repeated text here. This appears both in data # and in source. Anything you want can go here as long # as it repeats and you do these actions... # Substitute the variables back into the data. If you do # not like symbolic refs, you could use a hash instead, same # diff. This substitution builds source out of data. $t =~ s/-(\w+)/${$1}/g; # Since data is now source, just print it and we are done. print $t;
Of course it is also quite possible to make jokes that are quines. In fact I already did with the rather degenerate shortest one above. And here is another joke quine:
# This is a quine two :-) undef $/; $_ = <DATA>; print; print; __DATA__ # This is a quine two :-) undef $/; $_ = <DATA>; print; print; __DATA__
(Come on, give it a try. Quines are really quite fun. :-)

Replies are listed 'Best First'.
Re: Re (tilly) 1: Quine Whine
by danger (Priest) on Mar 06, 2001 at 22:30 UTC

    Well, here is an old standby:

    $_=q(print qq(\$_=q($_);eval\n));eval

    And here is a clever one I originally saw ages ago on clpm (posted by mjd I think, but I could be wrong about that). Save the following line to a file named "/tmp/p" and run as: perl /tmp/p

    Illegal division by zero at /tmp/p line 1.