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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |