在 Perl 中,如何获取当前执行代码的目录或路径? [英] In Perl, how do I get the directory or path of the current executing code?
本文介绍了在 Perl 中,如何获取当前执行代码的目录或路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在某个库代码中,如何确定当前正在执行的代码文件的路径?我知道如何通过查看 ARGV
来获取 top perl 文件的路径,但是如果我加载一个库,那个 library 怎么知道它在哪个路径?
If I am in some library code, how do I determine the path to the file of the code that is currently executing? I know how to get the path of the top perl file by looking at ARGV
, but if I load a library, how can that library know which path it is at?
推荐答案
__FILE__
标记将为您提供包括文件名的完整路径.您可以使用 File::Spec 将其拆分为多个组件:
The __FILE__
token will give you the full path including the file name. You can use File::Spec to split it into components:
my ($volume, $directory, $file) = File::Spec->splitpath(__FILE__);
这篇关于在 Perl 中,如何获取当前执行代码的目录或路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文