使用Perl打印当前目录 [英] Print current directory using Perl
本文介绍了使用Perl打印当前目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码使用Perl打印当前目录:
I have this code to print the current directory using Perl:
use Cwd qw(abs_path);
my $path = abs_path($0);
print "$path\n";
但是它正在显示我的脚本的文件名和目录。
But it is displaying the filename of my script along with the directory.
像这样:
C:\Perl\duration.pl
C:\Perl\duration.pl
我只想显示 C:\Perl\
。
我该怎么做?
推荐答案
脚本的目录,与当前目录不同。不清楚你想要哪一个。
The following get the script's directory, which is not the same as the current directory. It's not clear which one you want.
use FindBin qw( $RealBin );
say $RealBin;
或
use Cwd qw( abs_path );
use File::Basename qw( dirname );
say dirname(abs_path($0));
或
use Cwd qw( abs_path );
use Path::Class qw( file );
say file(abs_path($0))->dir;
这篇关于使用Perl打印当前目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文