Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: Self-printing program

by jpfarmer (Pilgrim)
on Apr 02, 2004 at 13:11 UTC ( [id://342066]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: Self-printing program
in thread Self-printing program

You're example using eval is excellent. I attempted something similar earlier, but my recursive call wasn't correct, but looking at your example, I understand why.

The other part of this program is to make the program output and arbitrary range of program lines, and trying to duplicate that code via the method I was using earlier was a real pain. Using this method, it should be much easier, although I wish I could execute code that was in an array directly, because it would make my life easier.

UPDATE: I implemented my existing code using this method, and it works very, very well. Thank you again for your help!

Replies are listed 'Best First'.
Re: Re: Re: Self-printing program
by etcshadow (Priest) on Apr 02, 2004 at 14:23 UTC
    Well, while this method is neat, note that it is not exactly the same thing as the recursion theorem. You should really understand the recurion theorem, or you'll probably be sorry, in the end.

    The simple way to add arbitrary code to a (recursion-theorem-based) quine is like so:

    $body = ' $body = %c%s%c; foo(); bar("baz"); printf($body,39,$body,39); '; foo(); bar("baz"); printf($body,39,$body,39);
    Note that, when doing it this way (as I mentioned), you end up having to duplicate the code (once to print it, and once to do it).
    ------------ :Wq Not an editor command: Wq

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://342066]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.