-1
我想相对于当前目录的路径拓展的首选方式:获得相对路径的绝对路径当前目录
use feature qw(say);
use strict;
use warnings;
use Cwd;
use File::Spec;
my $fn = 'test/my_file';
say File::Spec->rel2abs($fn);
say Cwd::abs_path($fn);
这里,Cwd::abs_path()
如果目录test
不存在失败。
为什么File::Spec->rel2abs()
工作正常,而Cwd::abs_path()
失败?
两个模块Cwd
和File::Spec
的文档没有提供这种情况的原因。根据下面的bug报告它可以从2004年是由于符号链接的扩展,第一:"Cwd::abs_path returns undef for non-existent paths"
:
感谢您参考'Path :: Class'! –