I have a program that is eval-ing the content of a lot strings

(Emphasis added.) Defining a new package name for each one is going to just keep adding memory consumption.

You might want to fork() and have the child evaluate the code. Or you might want to, every so often, re-exec the script to reset the memory consumption. Which is easier depends on which is more complicated: the data you get out of running the eval'd code or the program's "state" so that the new instance can properly continue where the prior instance left off.

use strict; my $pid = open my $pipe, "-|"; die "Can't fork: $!\n" if ! defined $pid; if( ! $pid ) { my $output = eval ...; print $output; exit; } local $/; my $output = <$pipe>; close $pipe;

Or

if( been_a_while() ) { system( $^X, $0, "--restart=$context", @ARGV ); }

- tye        


In reply to Re: Prevent import of subroutines from eval (fork or exec) by tye
in thread Prevent import of subroutines from eval by Swandog

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.