![](/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.