in reply to Odd eval Problem

As the perpetrator of that node, you could make the code shorter:
my $Hack = 'sub {' . $Subroutine->[2] . '}'; my $sub = eval "$Hack"; undef &{ *VWP_GenQueryHTML{CODE} }; *VWP_GenQueryHTML = $SubRef;
We've used a similar technique in Everything to speed up common page components, and haven't run into any trouble with eval "filling up". There are reports that certain versions of Perl have a leak in eval-string constructs, but it's more likely you'll run out of memory first.

There's no error checking to see if the compilation fails, and, if you're not extremely careful on the code from the database, it's easy to create some code that'll fail right off the bat

For example, if you have a comment as the last line of the code in the database, the interpreter won't see the closing brace of the subroutine declaration.

I'd definitely check $@ to see if the eval failed and I'd make sure $sub and &$sub are both defined before assigning to the glob.

Replies are listed 'Best First'.
Re: Re: Odd eval Problem
by nontrivial (Novice) on Jun 11, 2001 at 05:41 UTC
    chromatic,

    First off, thanks for the reply. Yes, I know I could make the code shorter, but somebody has to balance out brother Russ in a cosmic sense. :-)

    I believe I have been extremely careful moving the code to the database. For development I have been keeping all the code in one text file. The reason I think eval is "filling up" or whatever is that I have spent time moving various subroutines from the text file to the database. The only constant appears to be the size of the code in the database.

    Could I be running out of memory with no warning to indicate that? That might be a problem, as I have been using my somewhat underpowered laptop as the development server. And I will definately check $@.

    James
Re: Re: Odd eval Problem
by nontrivial (Novice) on Jun 11, 2001 at 20:01 UTC
    chromatic,

    It appears you put your finger on the problem. 6 of the 40+ subroutines are perfectly happy living in a text file, but for whatever reason when stuffed into a database and then pulled out and eval'd they don't like it very much. I suppose it is a bit degrading. :-) I should have been checking $@, and I was in other places, but oh well.

    It turns out that the 6 lame subroutines also happen to be some of the larger ones, which is why it seemed like I was "filling up" eval when I was experimenting.

    *sigh*

    Now all I have to do is figure out how to make eval happy. I'm already stumped on the first couple problem subroutines, but now that I know what the problem is it's only a matter of time. And this kind of blows in that user code (as opposed to my system code) will have to worry about this problem as well.

    Anyway brother chromatic, thank you very much for your wisdom and insight. :-)

    James