简体   繁体   English

如何在 Perl 的路径中将目录提升两级?

[英]How can I get the directory two levels up in a path in Perl?

How to go two directories up from an environment variable in perl?如何从perl中的环境变量向上移动两个目录?

sub do_file_tracing {
  my var = "$ENV{IMPORTANT_DIR}";

}

I want to create a file at long/path/to/the/important_dir long/path/to/the/important_dir/../../ , that is at long/path/to/我想在long/path/to/the/important_dir long/path/to/the/important_dir/../../处创建一个文件,即long/path/to/

Use Path::Tiny .使用Path::Tiny For example:例如:

use Path::Tiny;
my $dir = path($ENV{IMPORTANT_DIR})->parent(2);
my $dir_qfn = "$ENV{IMPORTANT_DIR}/../..";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM