我怎样才能在 Perl 的路径中获得两个级别的目录?

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

如何从 perl 中的环境变量向上移动两个目录?

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

}

我想在 long/path/to/the/important_dir long/path/to/the/important_dir/../../ 处创建一个文件,即 long/path/to/

使用Path::Tiny。例如:

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