Bug#839536: "do EXPR" no longer behaves as documented with '.' removed from @INC

Anthony DeRobertis anthony at derobert.net
Mon Oct 3 08:59:17 UTC 2016


On 10/02/2016 02:59 PM, Niko Tyni wrote:
> You snipped the 'except' part where it says it searches @INC directories.
> That implies it can't use the filename as-is but has to do some
> concatenation. The current working directory was never a special case,
> so things earlier on @INC would override the one in cwd.
>
> I'd say there's enough similarility in the behaviour apart from this that
> 'largely like' is not incorrect.

That is some interesting language lawyering, but really—you're saying 
it's "largely like", despite that one is going to execute the code in 
$CWD, but the other is going to fail? I mean, at best that example fails 
to illuminate (compare, for example, the code in the "require" section 
of the same pod). Also: of course, there is '/usr/share/perl5/stat.pl', 
so that was never really a good example.

It probably worth changing "do"'s behavior—having '.' in @INC certainly 
brought security issues, but of course most code uses "use" or "require" 
for module loading, not "do".

>
>> Surprisingly, even though the above works, this does not:
>>
>>      do 'subdir/file.pl'
>>
>> seems as if q{./} is doing something magical.
> 'subdir/file.pl' gets searched in @INC, './subdir/file.pl' doesn't because
> it's explicitly relative to cwd. This could indeed be documented better.

Indeed. I can't find any documentation of it at all.  It seems to 
prevent @INC search entirely, as

    $ perl -E 'do "./stat.pl"; say $!'
    No such file or directory

when it should find /usr/share/perl5/./stat.pl.

The same appears to apply to "require", though "require" is unaware of 
it, at least according to the error message:

    $ perl -E 'require "./stat.pl"'
    Can't locate ./stat.pl in @INC (@INC contains: /etc/perl
    /usr/local/lib/x86_64-linux-gnu/perl/5.24.1
    /usr/local/share/perl/5.24.1 /usr/lib/x86_64-linux-gnu/perl5/5.24
    /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.24
    /usr/share/perl/5.24 /usr/local/lib/site_perl
    /usr/lib/x86_64-linux-gnu/perl-base) at -e line 1.




More information about the Perl-maintainers mailing list