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

Re: The tricky issue of do()

Thread Previous | Thread Next
From:
Leon Timmermans
Date:
February 25, 2017 16:55
Subject:
Re: The tricky issue of do()
Message ID:
CAHhgV8icug7Gy9fm3j1G3++cR2fk21JRdP-sT26A5yxUNjrbrA@mail.gmail.com
On Tue, Feb 21, 2017 at 8:47 PM, Matt S Trout <mst@shadowcat.co.uk> 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.
>
> Which means simply saying "welp, . isn't in @INC anymore" is going to leave
> a vast number of broken scripts, most of them likely the ones whose users
> are least knowledgable about perl (do 'config.pl' is very common baby perl,
> I think).
>
> Also, if a do() user doesn't check $@ - and most don't realise to - they won't
> even see the "Can't find" error.
>
> I'm not sure what to do about this - my best thought so far is to have a
> warning that's emitted for "do 'file.pl'" where 'file.pl' exists in '.' but
> not in @INC that recommends switching to "do './file.pl'". I think that's
> better than 'apparently silent failure'. I don't know if there's a better
> option still.
>
> But I think lots and lots of people are going to have code that just
> suddenly, silently, doesn't work, on the current path, and I think that's
> something we should really try and address *somehow*.
>
> Thoughts?

The semantics of do are less than awesome, or better said utterly
confusing and often wrong for most purposes, but that is a
time-machine problem. The ironic thing is that this change breaks the
only case that most people care about. Complaining loudly sounds like
the least we can do.

Leon

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About