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

后端 未结 23 2960
情深已故
情深已故 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:57

    There's no need to use external modules, with just one line you can have the file name and relative path. If you are using modules and need to apply a path relative to the script directory, the relative path is enough.

    $0 =~ m/(.+)[\/\\](.+)$/;
    print "full path: $1, file name: $2\n";
    

提交回复
热议问题