首页 > 解决方案 > Linux - Perl - 文件不存在,但确实存在

问题描述

我有一个文件

/var/tmp/pcaps/言語をé¸æŠžã—ã¦ããŸã‚™.pcap'

这正是它的名字,它是用 UTF-8 编码的。

当我在上面运行 vim 时,它会按预期打开。

但是当我运行以下 perl 代码时:

    if (-e $target_file) {
            warn "the file exists\n";
    } else {
            warn "the file does not exist!\n";
    }

$target_file 正是上面提到的文件。它进入其他地方。

为什么会这样?

标签: linuxperl

解决方案


#use utf8;
my $file = 'è¨èªãé¸æãã¦ããã.pcap';
if(-e $file){
    print "exists\n";
}

这对我有用。也许尝试“使用 utf8;”

编辑:

检查 $target_file 的完整路径。也许有一个错误的字母/文件夹?


推荐阅读