Are there situations where rel2abs($0) returns somthing different than rel2abs(__FILE__)?

StackOverflow https://stackoverflow.com/questions/21073190

  •  27-09-2022
  •  | 
  •  

Question

Are there situations where these two says (rel2abs($0) and rel2abs(__FILE__)) return something different?

use 5.10.0;
use File::Spec::Functions qw(rel2abs);

say rel2abs($0);

say rel2abs(__FILE__);
Was it helpful?

Solution

  1. As tripleee mentioned, a program may consist of multiple __FILE__s.

  2. The $0 may be set to anything (depends on the OS):

    $0 = "foo bar";
    

Instead of using rel2abs, you might be interested in the FindBin module, especially the $FindBin::RealBin variable.

OTHER TIPS

If $0 is not __FILE__, they are different. This could happen if you require or use or do this file from another script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top