perl指令碼之目錄

來源:互聯網
上載者:User

標籤:

來源:

http://www.cnblogs.com/itech/archive/2013/02/20/2919204.html

 

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 "$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.

 

perl指令碼之目錄

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.