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

12,954

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.

Share:
12,954
James BAn
Author by

James BAn

A seasoned italian guy deeply in love with Hi-Tech, programming, math, physics and smart people.

Updated on June 17, 2022

Comments

  • James BAn
    James BAn almost 2 years

    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