in reply to Difference between $0 and __FILE__

This is an old question, but there's more of an answer. If a module is found in the current directory by matching '.' in @INC, then the value of __FILE__ is just the filename of the module with no path information. This is important if something does a chdir, then the module is no longer in "the current directory".

Replies are listed 'Best First'.
Re^2: Difference between $0 and __FILE__
by Your Mother (Archbishop) on Jul 21, 2017 at 05:32 UTC

    Good point; part of why I eschew chdir style code. A little more on your call out–

    package AB; # File: /Users/moo/AB.pm use strict; use Path::Tiny; sub ohai { __FILE__ } sub ohai_der { path(__FILE__)->absolute } 1;
    moo@cow[54]~>perl -MAB -le 'print AB->ohai; print AB->ohai_der' AB.pm /Users/moo/AB.pm
    moo@cow[55]~>perl -MAB -le 'chdir "/tmp"; print AB->ohai; print AB->oh +ai_der;' AB.pm /private/tmp/AB.pm