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

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

  •  27-09-2022
  •  | 
  •  

Domanda

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__);
È stato utile?

Soluzione

  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.

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top