This small program, quinify, produces a quining wrapper around any suitably simple perl program. The quined version writes its source to STDERR so that STDOUT remains available to the wrapped code. The program to wrap can be provided by a list of files on the command line,
$ quinify file1 file2 file3

through a pipe,
$ cat file.pl | quinify - | perl -w - 2>filequine.pl

or from the keyboard,
$ quinify >Quinequote
my $string = 'yields falsehood when preceded by its quotation';
print "'$string' $string.$/";
^D

Some of the usage is *nicentric.

'Suitably simple' means

  1. No use of the DATA filehandle.
  2. No verbosity over STDERR.
  3. No reliance on perl run options in the shebang line.
  4. Runs under strict and warnings.
If you notice other restrictions, please let me know. I'll add them to the list with credits.

Here's the code:

#!/usr/bin/perl -w use strict; { my @lines = map { chomp; $_ } <DATA>; # magical input permits interactive, piped, or # batch operation. push @lines, map { chomp; $_ } <>; { local $, = $/; print @lines,'__DATA__', reverse @lines; } } __DATA__ #!/usr/bin/perl -w use strict; { # This block prints the source to this program on stderr. # It quines there so that scripts which write to stdout # can operate unimpeded. Generated by quinify. my @ary= map { chomp; $_ } <DATA>; { local $,=$/; print STDERR reverse( @ary ), '__DATA__', @ary; } }
I use reverse to mung the source in data, mostly for visual effect. Any encryption-decryption scheme may be used, or none at all.

This may look familiar. I used a previous version, with a mildly obfuscated __DATA__ section, to quine There can be only one! in But There Are Two! .

After Compline,
Zaxo


In reply to Quine code with quinify by Zaxo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.