Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Quine code with quinify

by Zaxo (Archbishop)
on Oct 01, 2001 at 07:40 UTC ( [id://115789]=CUFP: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://115789]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-12-08 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (50 votes). Check out past polls.