![](/img/trans.png)
[英]How do i use -M flag to load a perl module using its relative path from command line?
[英]How do I convert a full path to a relative path using perl?
我在Perl程序中的两个变量中具有文件的完整路径和其父目录之一的完整路径。
什么是计算文件相对于父目录的相对路径的安全方法。 需要在Windows和Unix上工作。
例如
$filePath = "/full/path/to/my/file";
$parentPath = "/full";
$relativePath = ??? # should be "path/to/my/file"
它们具有abs2rel函数
my $relativePath = File::Spec->abs2rel ($filePath, $parentPath);
在Windows和Linux上均可使用
use Path::Class;
my $full = file( "/full/path/to/my/file" );
my $relative = $full->relative( "/full" );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.