来源:

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脚本之目录的更多相关文章

  1. 【转】FTP自动上传文件的perl脚本以及配置文件

    这个perl文件将执行的任务是, 按照指定的文件夹目录,自动将该文件夹下的所有文件上传到指定ftp站点的指定目录下 本应用程序设计的几个基本理念是:工具箱再利用:尽可能利用已有的工具:简化运行步骤:不 ...

  2. linux 全自动提权 exp perl脚本

    linux 全自动提权 exp perl脚本 作者: admin 日期: 2013/01/19发表评论 (0) 查看评论   国外流传过来的 地址 http://dl.packetstormsecur ...

  3. perl 脚本测试

      原文地址:  http://blog.csdn.net/johnny710vip/article/details/8905239   这是一篇关于perl脚本测试的总结性文章,其中提到了很多实用的 ...

  4. 使用Perl脚本编译Latex

    使用Perl脚本编译Latex 脚本能实现Latex文本的初级编译,并将生成的中间文件移动到同一个目录 调用方法 chmod +x xelatex2pdf.pl xelatex2pdf.pl -n 2 ...

  5. Apache服务器中运行CGI程序的方法,文中以Perl脚本作为示例

    关于apache与CGI在这里就不解释了. 1.apache下面以2.0.63为例介绍运行CGI程序的配置.(http://www.nklsyy.com) 2.下载Windows下的Perl解释器Ac ...

  6. crontab不执行perl脚本分析

    在新装的Linux服务器上部署了一个作业监控磁盘空间并提前告警,在shell脚本里面调用了一个perl脚本发送告警邮件.结果出现了一个很奇怪的现象:如果手工执行该脚本/home/oracle/scri ...

  7. python 获取脚本所在目录

    平时写python经常会想获得脚本所在的目录,例如有个文件跟脚本文件放在一个相对的目录位置,那就可以通过脚本文件的目录找到对应的文件,即使以后脚本文件移到其他地方,脚本也基本不需要改动(相对于写死目录 ...

  8. csv,txt,excel文件之间的转换,perl脚本

    最近接触一些需要csv,txt,excel文件之间的转换,根据一些网上搜索加上自己的改动,实现自己想要的结果为主要目的,代码的出处已经找不到了,还请见谅,以下主要是针对csv&excel 和t ...

  9. [置顶] perl脚本中defined,exists和delete关键字的用法和区别

    刚学习perl脚本的时候,喜欢频繁使用defined关键字判断一个hash中某个key是否存在,后来程序出了问题才去perl官方文档查看关于defined关键字的准确使用方法.因此,这里我把perl中 ...

随机推荐

  1. eclipse设置JSP的默认编码

    有时候我们新建一个JSP页面,但是编码却不是我们想要的,我们可在eclipse里面进行如下设置: 点击eclipse上面的window-->preferences 输入查找jsp-->点击 ...

  2. magento寄存器的使用

    1.Mage::register('validation_image_name', $validationImageName);//这个是把变量$validationImageName存储在valid ...

  3. screen 对象当当获取屏幕而已 innethtml可以知道调整屏幕宽度

    <div id='lidepeng' style="height: 100px;width: 100px;"></div><script type=& ...

  4. Apple 移动设备绑定动态生成元素点击事件$(document).on('click',element,callback)失效解决方法

    今天在工作中刚接触到了微信社区相关的开发工作,测试的时候发现,动态生成元素的点击事件在andriod设备上可以触发,而在apple移动设备上却无法触发.好奇的我赶紧百度了下,很快就在stackover ...

  5. css3制作导航栏

    <!doctype html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  6. Angular2,React集成

    https://www.packtpub.com/books/content/integrating-angular-2-react http://www.syntaxsuccess.com/view ...

  7. JVM基础02-class文件

    一.class文件结构 介绍之前,请下载一个Bytecode工具,例如byte code viewer或者Java Bytecode Editor,我用的是后者Java Bytecode Editor ...

  8. Java 相关注意事项小结

    程序是一系列有序指令的集合: Java主要用于开发两类程序: 1)桌面应用程序2)Internet应用程序1,Java程序:三步走,编写--编译--运行:2,使用记事本开发:1)以.java为后缀名保 ...

  9. .Net Core 中使用Session

    1.在 Startup 中 ConfigureServices 添加Session public void ConfigureServices(IServiceCollection services) ...

  10. 亲身体验:digitalocean vps能做的10件事

    我写过一篇亲身体验:digitalocean和linode评测哪个好,帮助不少网友选购价格便宜性能优异的免备案vps,相信大家对两家产品有所了解.vps的性能和用途远远超过传统的虚拟主机,你拥有独立I ...