develooper Front page | perl.perl5.porters | Postings from February 2017

Re: The tricky issue of do()

Thread Previous | Thread Next
Christian Walde
February 25, 2017 18:50
Re: The tricky issue of do()
Message ID:
On Tue, 21 Feb 2017 20:47:35 +0100, Matt S Trout <> wrote:

> Dealing with the fallout of removing '.' from @INC has been an interesting
> exercise, but in the case of require()d files, I think overall a worthy one.
> I'm rather less convinced about do().
> In fact, I didn't until very recently realise that do() searched @INC, my
> mental model of it had always been 'run this path and return the result',
> and every piece of code I've seen in the wild that used it appeared to be
> based on the same expectation.

It's not only your mental model, it is what is documented in perldoc, with the "searches @INC" part being worded as an addendum to the base functionality:

     Uses the value of EXPR as a filename and executes the contents of the file as a Perl script.

         do '';

     is largely like

         eval `cat`;

So in my opinion `do "thing"` should be modified to match perldoc for backwards compatibility, i.e. look in "." first, then @INC if that fails.

The point has been raised by haarg and leont that that might not be entirely straight-forward due to shared code between use/require, but i think in this case backwards compatibiliy should trump, even if the core code looks a little more ugly as a result.

And well, if you don't, please remember to fix up perldoc.

With regards,
Christian Walde

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About