打印使用Perl当前目录
1)
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 Cwd qw( abs_path );
useFile::Basename qw( dirname );
say dirname(abs_path($0));
or
usePath::Class qw( file );
say file($0)->absolute->dir;
or
useCwd qw( abs_path );
use Path::Class qw( file );
say file(abs_path($0))->dir;
The middle one handles symlinks different than the other two, I believe.
2)
To get the current working directory (pwd on many systems), you could use cwd() instead of abs_path:
useCwd qw();
my $path =Cwd::cwd();
print "$path\n";
Or abs_path without an argument:
useCwd qw();
my $path =Cwd::abs_path();
print "$path\n";
See the Cwd docs for details.
To get the directory your perl file is in from outside of the directory:
useFile::Basename qw();
my($name, $path, $suffix)=File::Basename::fileparse($0);
print "$path\n";
See the File::Basename docs for more details.
3)
You could use FindBin:
use FindBin '$RealBin';
print "$RealBin\n";
FindBin is a standard module that is installed when you install Perl. To get a list of the standard pragmatics and modules, see perldoc perlmodlib.
完!
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/jiaob/perl/8916.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
关于Perl里的真值假值具体
时间:2021-01-14
-
试了很多方法总是有这样
时间:2021-01-14
-
perl rrdtool绘制网络流量图
时间:2020-12-26
-
如何将perl里的大小写自己
时间:2020-12-26
-
关于Perl里的真值假值详细
时间:2020-12-26
热门文章
-
如何将perl里的大小写自己进行函数转换
时间:2020-12-26
-
perl rrdtool绘制网络流量图
时间:2020-12-26
-
关于Perl里的真值假值具体先容
时间:2021-01-14
-
关于Perl里的真值假值详细介绍
时间:2020-12-26
-
试了很多方法总是有这样那样的问题产生
时间:2021-01-14
