Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

This turned out not to be the disaster I expected

by Dominus (Parson)
on Jun 06, 2007 at 19:28 UTC ( #619650=perlmeditation: print w/replies, xml ) Need Help??

I was initially thinking about a module that would generate and execute every possible piece of Perl code when it was loaded. Such a module would be very useful, because once you loaded it, you wouldn't have to actually run your program; it would already have done whatever it was that you wanted.

As a first cut, I wrote:

$s = "a"; while (length($s) < 100) { eval $s; $s++ }
realizing that this wasn't going to be what I wanted, because it doesn't generate any code with spaces or punctuation, but I thought it might be fun, at least as a joke. It looks like it is going to take a long time to execute, so I ran it with some fear that it might crash my machine or do something else bad.

But actually it executes rather quickly, and nothing bad happens. As I said, it was not the disaster I expected.

Can you predict the results?

Replies are listed 'Best First'.
Re: This turned out not to be the disaster I expected
by imp (Priest) on Jun 06, 2007 at 19:39 UTC
Re: This turned out not to be the disaster I expected
by kyle (Abbot) on Jun 06, 2007 at 19:41 UTC
Re: This turned out not to be the disaster I expected
by shmem (Chancellor) on Jun 06, 2007 at 21:36 UTC

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: This turned out not to be the disaster I expected
by BrowserUk (Pope) on Jun 06, 2007 at 19:37 UTC
Re: This turned out not to be the disaster I expected
by naikonta (Curate) on Jun 07, 2007 at 02:53 UTC
    This can be a way to find a c00l n4m3 or some magic number?
    perl -le '$s = shift; while (length($s) < 100) { print $s; eval $s; $s +++; }'
    But this one is less fun :-)
    perl -le '$s = shift; while (length($s) < 100) { print $s; eval $s; $s +++; }' 'kill 9, $$'

    Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Re: This turned out not to be the disaster I expected
by djp (Hermit) on Jun 07, 2007 at 03:03 UTC
    I'm predicting you hit '?' early in the piece. Update: didn't hide my answer as others did.

      No, because magical autoincrement on alphanumeric strings never strays outside the alphanumeric character set.

Re: This turned out not to be the disaster I expected
by ambrus (Abbot) on Jun 10, 2007 at 00:23 UTC

    Update: Ok, let me think this over again after reading the other replies.

    Firstly, I realized that fork wouldn't cause a fork bomb as I thought for some reason, only fork exactly once. Now I didn't realize getc would do something significant (as opposed to, say, warn which just prints some output) until I've read FunnyMonk's reply. So this means that if we get over dump and exit, the script would fork exactly once and then try to read the terminal from both processes. This is not the typical job control situation, because the two interpreters are in the same process group, so I have to look it up in the manual what happens exactly. *looks it up* I can't find it out from the manual. Let me try. *tries* Apparently nothing special happens, they read lines after each other in some random order.

    Secondly, I realized that I thought of redo but not last or next. last would obviously exit the loop and thus end the program. next would also cause an infinite loop the same way as redo, but this could be avoided by putting the $s++ in a continue block.

    Of course, none of these change my answer being dump.

Re: This turned out not to be the disaster I expected
by gaal (Parson) on Jun 07, 2007 at 16:29 UTC
    I seem to vaguely recall someone discovering this sometime in the 90ies, maybe even on c.l.p.m.
Re: This turned out not to be the disaster I expected
by diotalevi (Canon) on Jun 09, 2007 at 00:29 UTC

    It leaks memory while it's working.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://619650]
Approved by imp
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2021-04-16 09:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?