in reply to require vs eval

I'm not very familiar with the internals of perl, but logic suggests that require is essentially eval where the data to be eval'd comes from a file. Therefore, the evaluation (parsing, compiling etc) of the text will take the same amount of time either way.

The difference will be the overhead in writing the text to a file only to read it back in.

There's more to it than that, but all of that "more to it" is additional overhead on the require, making the eval look even better.

That said, I'd like to see the code you are evaling. 5 gets you 2 that there is a better way:)


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


Replies are listed 'Best First'.
Re: Re: require vs eval
by antirice (Priest) on Jun 16, 2003 at 21:52 UTC

    Ah, you're absolutely right BrowserUK. Straight from perldoc -f require:

    ...Otherwise, demands that a library file be included if it hasn't already been included. The file is included via the do-FILE mechanism, which is essentially just a variety of eval...

    In other words, DOH! *slaps own hand for RTFM for eval but not for require*

    antirice    
    The first rule of Perl club is - use Perl
    The
    ith rule of Perl club is - follow rule i - 1 for i > 1