How do I get the full path to a Perl script that is executing?

后端 未结 23 3013
情深已故
情深已故 2020-11-28 19:29

I have Perl script and need to determine the full path and filename of the script during execution. I discovered that depending on how you call the script $0 va

23条回答
  •  长情又很酷
    2020-11-28 19:43

    $0 is typically the name of your program, so how about this?

    use Cwd 'abs_path';
    print abs_path($0);
    

    Seems to me that this should work as abs_path knows if you are using a relative or absolute path.

    Update For anyone reading this years later, you should read Drew's answer. It's much better than mine.

提交回复
热议问题