加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl脚本的目录

发布时间:2020-12-16 00:16:08 所属栏目:大数据 来源:网络整理
导读:http://stackoverflow.com/questions/5703705/print-current-directory-using-perl?rq=1 ? 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 ); u

http://stackoverflow.com/questions/5703705/print-current-directory-using-perl?rq=1

?

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 "$pathn";

Or abs_path without an argument:

useCwd qw();

my $path =Cwd::abs_path();

print "$pathn";

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 "$pathn";

See the?File::Basename?docs for more details.

?

3)

You could use?FindBin:

use FindBin '$RealBin';

print "$RealBinn";

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.

?

完!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读