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

[perl #131100] The "../" relative path misbehaving with regard todefault_inc_excludes_dot

Thread Next
From:
Karl Williamson via RT
Date:
April 8, 2017 17:19
Subject:
[perl #131100] The "../" relative path misbehaving with regard todefault_inc_excludes_dot
Message ID:
rt-4.0.24-18605-1491671946-1982.131100-15-0@perl.org
On Wed, 05 Apr 2017 02:03:33 -0700, haarg wrote:
> On Wed, Apr 5, 2017 at 9:31 AM, Dave Mitchell <davem@iabyn.com> wrote:
> > On Tue, Apr 04, 2017 at 01:04:36PM -0700, Andreas J. Koenig via RT
> > wrote:
> >> "../foo" seems not to be regarded as a relative path, leading to
> >> this bug:
> >>
> >> perl -e '
> >> use File::Temp qw(tempdir);
> >> my $tmpdir = tempdir("tXXXX", CLEANUP => 1);
> >> chdir $tmpdir;
> >> open my $fh, ">", "do_this.pl";
> >> print $fh qq{print "not ok # executed from within
> >> ../$tmpdir/do_this.pl\\n";\n};
> >> close $fh;
> >> do "../$tmpdir/do_this.pl";
> >> '
> >> not ok # executed from within ../ty2En/do_this.pl
> >>
> >>
> >> Expected behaviour would be to see a warning like
> >>
> >> do "../ty2En/do_this.pl" failed, '.' is no longer in @INC; did you
> >> mean do "./../ty2En/do_this.pl"? at -e line 8.
> >
> > This has been the behaviour of do (and require) since at least 5.6.1:
> >
> > $ pwd
> > /home/davem/tmp/x
> >
> > $ cat foo.pl
> > 1;
> >
> > $ cat ~/tmp/p
> > #!perl
> > #
> > @INC=();
> > for ("", "./", "../x/") {
> >     my $f = "${_}foo.pl";
> >     my $ok = (do $f) ? "ok" : "not ok";
> >     printf "%12s %s\n", $f, $ok;
> > }
> >
> > $ perl561o ~/tmp/p
> >       foo.pl not ok
> >     ./foo.pl ok
> >  ../x/foo.pl ok
> >
> > $ perl52511 ~/tmp/p
> > do "foo.pl" failed, '.' is no longer in @INC at /home/davem/tmp/p
> > line 6.
> >       foo.pl not ok
> >     ./foo.pl ok
> >  ../x/foo.pl ok
> >
> > I expect this behaviour is intentional (although to 'do' pod entry is
> > silent on the matter). Should we change the behaviour now?
> 
> It is definitely intentional behavior.  Both do and require have a
> special case for paths starting with './' or '../'.  The do
> documentation mentions './' now, but the other cases aren't documented
> at all.

This should be documented, as it apparently has confused some people.

-- 
Karl Williamson

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=131100

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