Perl 如何获取当前程序文件的绝对目录?
发表于 : 2009-05-31 11:13
RT
谢谢大家的帮助
谢谢大家的帮助
代码: 全选
#!/usr/bin/perl
use Cwd;
use File::Basename;
my $cwd;
if ($0 =~ m{^/}) {
$cwd = dirname($0);
} else {
$cwd = dirname(getcwd()."/$0");
}
print "$cwd\n";
$0的值取决于运行程序是输入的路径 (相对路径和绝对路径)我想要的是绝对路径。。。。。。。。。。。。eexpress 写了:$0 包含正在执行的脚本的文件名 ?
代码: 全选
use File::Spec::Functions qw(rel2abs);
use File::Basename qw(dirname);
print dirname( rel2abs( __FILE__ ) );