为什么 Perl 会抱怨“包含换行符的文件名统计失败"? [英] Why does Perl complain about "Unsuccessful stat on filename containing newline"?

查看:61
本文介绍了为什么 Perl 会抱怨“包含换行符的文件名统计失败"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一个我不明白的错误.我正在使用 File:Find 在 Windows 上使用 Activestate Perl 5.8.8 递归 fylesystem 并尝试统计 $File::Find::name;所以我不是 stat-ing 从需要 chomp-ing 或换行删除的文本文件扫描中获得的文件名.我无法获得文件修改时间,mtime 在:

I am getting an error I do not understand. I am using File:Find to recurse a fylesystem on Windows using Activestate Perl 5.8.8 and trying to stat $File::Find::name; so I am not stat-ing a filename got from a text file scanning requiring chomp-ing or newline removing. I was unable to get file modification time, the mtime in:

my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($File::Find::name);

所以尝试

-s $File::Find::name 

给我错误:

包含换行符的文件名统计失败

Unsuccessful stat on filename containing newline

找到的典型文件名是 F01-01-10 Num 0-00000.pdf 但即使在 E02.pdf

A typical file name found is F01-01-10 Num 0-00000.pdf but I get the same error even renaming in E02.pdf

推荐答案

根据 perldiag 如果任何文件操作失败并且文件名恰好包含换行符,将发出警告文件名包含换行符不成功".

According to perldiag if any file operation fails and the filename happens to contain a newline character, the warning "Unsuccessful on filename containing newline" will be emitted.

假设是,如您所说,文件名来自标准输入或类似输入,而用户忘记了 chomp 换行符.无论如何,您可能希望通过 chomp 传递字符串,只是为了看看它是否有效.

The assumption is that, as you say, the filename has come from standard input or similar, and the user has forgotten to chomp the newline away. You might want to pass the string through chomp anyway, just to see if it works.

一些证据表明&CORE::stat mtime 可能会因操作系统补丁级别和 ActiveState Perl 版本的某些组合而损坏 - 建议的解决方法是使用 File::stat 模块如下:

There is some evidence that &CORE::stat mtime might be broken with some combinations of OS patchlevel and ActiveState Perl versions - a suggested workaround is to use the File::stat module like so:

my $sb = stat($File::Find::name);
my $mtime = scalar localtime $sb->mtime;

...你可能会发现 File::stat 的对象表示比 CORE::stat 返回的列表更方便.

...you might find File::stat's object representation to be more convenient than the list returned by CORE::stat.

这篇关于为什么 Perl 会抱怨“包含换行符的文件名统计失败"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆