perl脚本之目录
来源:
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 ); #推荐
use File::Basename qw( dirname ); #推荐 my $flk = abs_path($); #F:/EclipseTest2/a/test1.pl
my $flk2 = dirname($flk); #F:/EclipseTest2/a say $flk2; #必须有use v5.10; 才能用say
or
use Path::Class qw( file ); #我的系统上没有Path::Class模块。需要通过ppm安装一下就有了。本人不推荐用这个,因为产生的都是windows样式的分隔符
say file($)->absolute->dir; #结果 F:\EclipseTest2\a (windows样式的分隔符)
or
use Cwd qw( abs_path );
use Path::Class qw( file );
say file(abs_path($))->dir; #结果 F:\EclipseTest2\a(windows样式的分隔符)
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:
use Cwd qw();
my $path =Cwd::cwd();
print "$path\n"; #结果 F:/EclipseTest2/a
Or abs_path without an argument:
use Cwd qw();
my $path =Cwd::abs_path();
print "$path\n"; #结果 F:/EclipseTest2/a
See the Cwd docs for details.
To get the directory your perl file is in from outside of the directory:
use File::Basename qw();
my($name, $path, $suffix)=File::Basename::fileparse($);
print "$path\n"; #F:/EclipseTest2/a/ 多一个/ 其实$name为test1.pl $suffix为
See the File::Basename docs for more details.
3)
You could use FindBin:
use FindBin '$RealBin'; #推荐
print "$RealBin\n"; #F:/EclipseTest2/a FindBin sets both $Bin and $RealBin to the current directory.
FindBin is a standard module that is installed when you install Perl.
perl脚本之目录的更多相关文章
- 【转】FTP自动上传文件的perl脚本以及配置文件
这个perl文件将执行的任务是, 按照指定的文件夹目录,自动将该文件夹下的所有文件上传到指定ftp站点的指定目录下 本应用程序设计的几个基本理念是:工具箱再利用:尽可能利用已有的工具:简化运行步骤:不 ...
- linux 全自动提权 exp perl脚本
linux 全自动提权 exp perl脚本 作者: admin 日期: 2013/01/19发表评论 (0) 查看评论 国外流传过来的 地址 http://dl.packetstormsecur ...
- perl 脚本测试
原文地址: http://blog.csdn.net/johnny710vip/article/details/8905239 这是一篇关于perl脚本测试的总结性文章,其中提到了很多实用的 ...
- 使用Perl脚本编译Latex
使用Perl脚本编译Latex 脚本能实现Latex文本的初级编译,并将生成的中间文件移动到同一个目录 调用方法 chmod +x xelatex2pdf.pl xelatex2pdf.pl -n 2 ...
- Apache服务器中运行CGI程序的方法,文中以Perl脚本作为示例
关于apache与CGI在这里就不解释了. 1.apache下面以2.0.63为例介绍运行CGI程序的配置.(http://www.nklsyy.com) 2.下载Windows下的Perl解释器Ac ...
- crontab不执行perl脚本分析
在新装的Linux服务器上部署了一个作业监控磁盘空间并提前告警,在shell脚本里面调用了一个perl脚本发送告警邮件.结果出现了一个很奇怪的现象:如果手工执行该脚本/home/oracle/scri ...
- python 获取脚本所在目录
平时写python经常会想获得脚本所在的目录,例如有个文件跟脚本文件放在一个相对的目录位置,那就可以通过脚本文件的目录找到对应的文件,即使以后脚本文件移到其他地方,脚本也基本不需要改动(相对于写死目录 ...
- csv,txt,excel文件之间的转换,perl脚本
最近接触一些需要csv,txt,excel文件之间的转换,根据一些网上搜索加上自己的改动,实现自己想要的结果为主要目的,代码的出处已经找不到了,还请见谅,以下主要是针对csv&excel 和t ...
- [置顶] perl脚本中defined,exists和delete关键字的用法和区别
刚学习perl脚本的时候,喜欢频繁使用defined关键字判断一个hash中某个key是否存在,后来程序出了问题才去perl官方文档查看关于defined关键字的准确使用方法.因此,这里我把perl中 ...
随机推荐
- android 5.0 -- 主题
系统提供默认的三种主题样式 @android:style/Theme.Material (dark version) @android:style/Theme.Material.Light (ligh ...
- Linux服务器导入导出SVN项目
导出项目: # svnadmin dump /var/svn/pro1 > /mydata/pro1.backup 导入项目: 新建项目仓库: # svnadmin create /var/sv ...
- Spring 后置处理器 PropertyPlaceholderConfigurer 类(引用外部文件)
一.PropertyPlaceholderConfigurer类的作用 PropertyPlaceholderConfigurer 是 BeanFactory 后置处理器的实现,也是 BeanFact ...
- JavaScript详解
JavaScript可以说是web开发中必备的一种技术.它具有灵活,简单,高效等特点.这次DRP中大量的用到了js,让自己对js有了更深的了解.看完这个以后还回去看了一下牛腩的js视频.把以前没看的看 ...
- 我的linux云服务器配置记录
配置vps的时候,随手记录一下~~ 添加一些源: vi /etc/apt/sources.list deb http://mirrors.aliyun.com/ubuntu/ xenial main ...
- 第三节,入门知识和windows系统安装python环境
1.使用Linux的好处(稳定)不容易死机,可以长达几年不间断运行(安全)相对windows系统更安全,相对更不容受到各种攻击(开源)免费使用2.安装好虚拟机VMware软件,和Linux系统,以及X ...
- 关于input在li列表中居中显示
input属于置换元素(replaced element),置换元素主要是指img,input,textarea,select,object等这类默认就有CSS格式化外表范围的元素,这些元素的垂直居中 ...
- 丢掉鼠标-Mac神软Alfred使用手册
上篇: http://wellsnake.com/jekyll/update/2014/06/15/001/?utm_source=tuicool 下篇: http://wellsnake.com/j ...
- CSS,height:auto和height:100%有什么区别?
auto是随内容的高度而撑开的.100%是根据父级元素的高度来决定的.例如:<div style="height:100px;width:200px;"> <di ...
- Xcode7修改模块生成网络权限(ATS配置)
直接找 前往->前往文件夹->然后复制下面的路径填入框内,回车就能看到想要替换的文件夹了 /Applications/Xcode.app/Contents/Developer/Pla ...