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中 ...
随机推荐
- Jmeter学习笔记
Jmeter安装 Jmeter组件介绍 Jmeter
- STM32笔记总结
1.命名规则 2.#pragma pack使用 #pragma pack 1保证字节对齐 置结构体的边界对齐为1个字节,也就是所有数据在内存中是连续存储的struct s{ char ch; ...
- c# 使用 HttpWebRequest模拟登陆
c# 使用 HttpWebRequest模拟登陆(附带验证码) 分类: C# .net2010-06-04 00:50 35647人阅读 评论(43) 收藏 举报 c#exceptionstreams ...
- ajaxFileUpload 报这错jQuery.handleError is not a function
今天刚打个一个技术群,里面有人问标题上的问题,嘿,我恰好遇过,现在大家至少也在用jquery1.9以上的版本,ajaxfileupload的版本早就不更新了,大家可以下载看:地址这里, 它例子里使用的 ...
- haskell类型
一.源文件 介绍这个主要是因为下文很多代码写在源文件中,然后从ghci加载源文件进行测试. 创建一个文本文件,在其中输入,并保存为add.hs文件 -- file: add.hs add x y = ...
- putty 中使用git
提交git pwd 查看当前目录 进入目录cd /home/gongfu/tripb/master 修改代码目录 git status 查看 修改的文件(新增的,删除的) git commit -m ...
- 14.hibernate的反向生成实现全套增删改查
图片顺序就是步骤顺序 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18.
- AR9531的mac地址
root@OpenWrt:/# ifconfigbr-lan Link encap:Ethernet HWaddr 00:11:22:34:56:78 inet addr ...
- AUTO_INCREMENT列在InnoDB里如何工作
如果你为一个表指定AUTO_INCREMENT列,在数据词典里的InnoDB表句柄包含一个名为自动增长计数器的计数器,它被用在为该列赋新值.自动增长计数器仅被存储在主内存中,而不是存在磁盘上. Inn ...
- LeetCode OJ 120. Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...