Re: Idea / preRFC - return value of require

[email protected] ("Paul \"LeoNerd\" Evans")
Newsgroups perl.perl5.porters
Message-ID <[email protected]>
On Thu, 12 Feb 2026 14:35:52 +0100
Branislav Zahradník <[email protected]> wrote:

> Expectation:
> - first call of function will load specified module
> - subsequent call of function will always return same value as first
> call
> 
> Current behaviour:
> - subsequent call returns value true if require was successful
> - if package-block is used, it doesn't return value of last statement
> of block but only logical true/false

It is this way intentionally.

Otherwise, you have the problem of unexpected extra reference counts of
returned values. If your final statement in the file scope yields some
large data structure, or object that's supposed to have timely
destruction semantics, or somesuch, then the cache will retain it for
too long.

If you did want a way to load a FILE and reliably return the value from
its final expression, you wanted `do FILE`.

-- 
Paul "LeoNerd" Evans

[email protected]
http://www.leonerd.org.uk/  |  https://metacpan.org/author/PEVANS
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.