简体   繁体   中英

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?

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/

Use Path::Tiny . For example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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