perl脚本的目录
来源:互联网 发布:淘宝无线端详情加链接 编辑:程序博客网 时间:2024/05/17 12:00
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脚本的目录
- 清空.svn目录的Perl脚本
- perl 获取当前脚本的目录
- Perl的目录操作
- Perl 脚本的特点
- 简单的perl脚本
- 一个用FTP批量上传文件的perl脚本,支持目录上传
- perl脚本之__分类统计某一目录下指定类型文件的大小
- 支持自动TOC超文本目录生成的chm转换器(perl脚本)
- 支持自动TOC超文本目录生成的chm转换器(perl脚本)
- Perl脚本:列出目录下所有的文件扩展名(后缀名)
- Perl 脚本在给定的文件夹目录中递归查找文件
- MD5验证的Perl脚本
- Perl脚本的调试方法
- 远程blast的Perl脚本
- perl 脚本
- perl脚本
- Perl入门(七) Perl脚本的调试
- 为什么使用tmux
- wine下安装wine
- 免费的 jQuery UI 主题集合
- Python-Django的windows环境
- 在vim中使用perltidy美化perl代码
- perl脚本的目录
- Linux 中用 strace 追踪系统调用和信号值
- perl通过文件锁让脚本单实例运行
- Linux下的SSH端口转发
- Perl 之 use(), require(), do(), %INC and @INC
- C++中调用库函数实现快速排序
- Linux技术blogs
- 订阅本博客itech.cnblogs.com
- Android UI控件之ListView实现圆角效果