perl program that outputs itself 
Author Message
 perl program that outputs itself

hi,

here is a little perl program i wrote that outputs its own source
code.
i gave this as an exercise to my pupils but nobody solved the problem.
hope you find it funny:

---- autograph.pl -----

$a='print chr(36).chr(97).chr(61).chr(39)
.$a.chr(39).chr(59).chr(10).$a;';
print chr(36).chr(97).chr(61).chr(39)
.$a.chr(39).chr(59).chr(10).$a;

--------------------------

joachim

ps: maybe we should create a new programming paradigm:
 in "autographic programming", every program/module/class must be able
to output its own source code on request :-)



Mon, 17 May 2004 14:54:50 GMT  
 perl program that outputs itself
How about this?

open SELF, "<$0"; print <SELF>;

But the script must be saved to a file, -e / STDIN will not work with
this :-(

--
  Simon Oliver



Mon, 17 May 2004 15:06:58 GMT  
 perl program that outputs itself
what about ...
print `cat script.pl`;
Quote:

> hi,

> here is a little perl program i wrote that outputs its own source
> code.
> i gave this as an exercise to my pupils but nobody solved the problem.
> hope you find it funny:

> ---- autograph.pl -----

> $a='print chr(36).chr(97).chr(61).chr(39)
> .$a.chr(39).chr(59).chr(10).$a;';
> print chr(36).chr(97).chr(61).chr(39)
> .$a.chr(39).chr(59).chr(10).$a;

> --------------------------

> joachim

> ps: maybe we should create a new programming paradigm:
>  in "autographic programming", every program/module/class must be able
> to output its own source code on request :-)



Mon, 17 May 2004 15:35:22 GMT  
 perl program that outputs itself

Quote:

> How about this?

> open SELF, "<$0"; print <SELF>;

> But the script must be saved to a file, -e / STDIN will not work with
> this :-(

yes. if i copy&paste this script and run it, it will *not* output itself.

but that's half a solution :-)



Tue, 18 May 2004 09:52:02 GMT  
 perl program that outputs itself

Quote:

> what about ...
> print `cat script.pl`;

hey, that's really clever!
but it cannot be adapted to C or most other languages.

joachim



Tue, 18 May 2004 09:53:28 GMT  
 perl program that outputs itself

Quote:

> hi,

> here is a little perl program i wrote that outputs its own source
> code.
> i gave this as an exercise to my pupils but nobody solved the problem.
> hope you find it funny:

> ---- autograph.pl -----

> $a='print chr(36).chr(97).chr(61).chr(39)
> .$a.chr(39).chr(59).chr(10).$a;';
> print chr(36).chr(97).chr(61).chr(39)
> .$a.chr(39).chr(59).chr(10).$a;

> --------------------------

> joachim

> ps: maybe we should create a new programming paradigm:
>  in "autographic programming", every program/module/class must be able
> to output its own source code on request :-)

A program that outputs itself is called a quine.

A note to those others who've lready posted followups:  Reading your own
source code to print it is considered cheating, so those aren't valid
quines [autograph.pl above is a valid quine, though].  The following
[assuming it works, it's untested] is technically a cheat.


Can any of you see how this is supposed to work? :)

You can see a bunch real quines and some cheats at:

http://www.nyx.net/~gthompso/self_perl.txt

Here's a couple of quines from the Fun With Perl mailing list:

by Kevin Reid:

xqvkliwCi0vsolfh+Ci0vkliw,>vsolfhCi07;030rug+%_q%,>

v2+u_+-B,+_g/,+_,,2'41+'5/4,1'62jh>hydo*~*1u1u+7,>


QRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz|~
NOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz

Quote:
};eval

by Pete Sergeant [in response to the one above]:
($_='Yw_xUabcdtefgdijktljkotiersjkUzxT
yvlkbfdtcierstajogvPruntRshackRJelov')
=~y/RTUv;wxYz$/ ~'\/;$=();/;eval;print

--
Klein bottle for rent - inquire within.



Fri, 21 May 2004 07:06:21 GMT  
 perl program that outputs itself

Quote:
> A note to those others who've lready posted followups:  Reading your own
> source code to print it is considered cheating, so those aren't valid
> quines [autograph.pl above is a valid quine, though].  The following
> [assuming it works, it's untested] is technically a cheat.



It doesn't work on my Win32 or Linux box.

But if it did it would be reading the source code - the second element
of the array returned by caller would be the filename of the package.

--
  Simon Oliver



Fri, 21 May 2004 13:25:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. redirecting output from one perl script to a file (withough changing the perl script itself)

2. program that prints itself

3. Program Output Handling in perl

4. system/pipe hang on large output perl program

5. forcing output to terminate a program (perl on win32)

6. Piping input to output of a program through a Perl filter

7. Intercepting the Mail output with a Perl program

8. Using Perl Output in Java Programming

9. sending mail of output from perl program

10. Lack of newlines in browser output from perl program

11. Parsing output from a program called within perl

12. Capturing output from a program in PERL

 

 
Powered by phpBB® Forum Software