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中 ...
随机推荐
- 湖南多校对抗赛(2015.05.03)Problem A: Twenty-four point
给四个数 问能不能算出24点...我的方法比较烂...920ms 差点TLE.应该有更好的方法. #include<stdio.h> #include<string.h> #i ...
- Android Monkey 测试策略【转】
Monkey 测试针对不同的对象和不同的目的,需要采用不同的测试方案. 首先测试的对象.目的及类型如下: 测试的类型 应用程序的稳定性测试 应用程序的压力测试 测试对象 单一 apk apk 集合 测 ...
- 使用UGUI实现拖拽功能(拼图小游戏)
实现方式 1.引入UGUI自带的事件系统 UnityEngine.EventSystems 2.为我们的类添加接口 IBeginDragHandler, IDragHandler, IEndDragH ...
- 获取 Windows 任务栏 Rect
获取当前Windows系统的任务栏尺寸 1: RECT rect; 2: HWND hwndTaskbar = FindWindow(TEXT("Shell_TrayWnd"), ...
- mnesia
1.模式创建 mnesia:create_schema([node()|nodes()]).集群的节点之间创建模式 2.启动和停止 application:start(mnesia). applica ...
- linux配置永久ip不生效解决方法
本文原文来自 http://blog.csdn.net/zymx14/article/details/51472239 linux下使用ifconfig eth0 ip地址可以设置ip地址 ,命令为: ...
- 浅析js模板引擎
js模板引擎越来越多的得到应用,如今已经出现了几十种js模板引擎,国内各大互联网公司也都开发了自己的js模板引擎(淘宝的kissy template,腾讯的artTemplate,百度的baiduTe ...
- this is it
hello everyone: 我是光哥.以后就在这里更新博客了.^_^ 主要更新一些学习记录,再加点别的吧 2015-8-21 许昌 申庄 吃饭去了,下午2:27的车去郑州!
- over 分析函数之 lag() lead()
/*语法*/ lag(exp_str,offset,defval) over() 取前 Lead(exp_str,offset,defval) over() 取后 --exp_str要取的列 -- ...
- 在自学php的路上不知道怎么走!!
在自学php的路上不知道怎么走!! 真希望有人给我指点一二!!!