Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Perl complain about "Unsuccessful stat on filename containing newline"?

Tags:

windows

perl

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);

so trying a

-s $File::Find::name 

gives me the error:

Unsuccessful stat on filename containing newline

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

like image 555
Daniel Avatar asked Apr 16 '10 10:04

Daniel


1 Answers

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.

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.

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;

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

like image 165
rjh Avatar answered Nov 15 '22 07:11

rjh