我在CentOS上有一个perl脚本,正在尝试使用File :: Slurp读取文件:

my $local_filelist = '~/filelist.log';
use File::Slurp;
my @files = read_file($local_filelist);


但我收到以下错误:

Carp::croak('read_file \'~/filelist.log\' - sysopen: No such file or directory') called at /usr/local/share/perl5/File/Slurp.pm line 802


尽管事实上我以myuser和以下身份运行脚本:

(2013-07-26 06:55:16 [myuser@mybox ~]$ ls -l ~/filelist.log
-rw-r--r--. 1 myuser myuser 63629044 Jul 24 22:18 /home/myuser/filelist.log


这是在CentOS 6.4的perl 5.10.1 x86_64上。

是什么原因造成的?

最佳答案

只需使用glob函数。这就是它的目的。

my $local_filelist = glob '~/filelist.log';

关于perl - 即使我拥有该文件并且对所有人都有读取权限,也没有“没有这样的文件或目录”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17879614/

10-12 21:16