strredwolf has asked for the wisdom of the Perl Monks concerning the following question:

Lets say I have a varible, $c, which contains some self-modifying perl code. Will perl get confused if I do:

while(eval $c) {}
So that the code in $c will be changed every eval, yet it'll return a 1 for another iteration or 0 for when it's done. I'm thinking of a compression algorithm.

--
$Stalag99{"URL"}="http://stalag99.keenspace.com";

Replies are listed 'Best First'.
Re: while(eval $c){} with self-modifying $c.
by chromatic (Archbishop) on Nov 24, 2000 at 21:47 UTC
    I have to agree with Dominus here. It's non-trivial to write a program that writes valid Perl. Save it for when you really need it.

    I'll go further, and guess that you'll be switching back and forth between n possible code snippets, where n is less than 100. In that case, use coderefs and an array or hash:

    my @code = ( sub { print "This does something!\n" }, sub { print "This also does something!\n" }, ); for (@code) { $_->(); }
Re: while(eval $c){} with self-modifying $c.
by Dominus (Parson) on Nov 24, 2000 at 21:08 UTC
    Perl won't get confused, but you might!

    I can't believe that this is the best way to accomplish whatever you're trying to do.

      It's an idle throught. I was thinking of the code in $c progressively expanding out $c itself. So eval will copy $c eval that copy? Hmmm...

      --
      $Stalag99{"URL"}="http://stalag99.keenspace.com";