Why does Perl complain about "Failed stat on file name containing new line"?

I get an error that I do not understand. I use File: Find to overwrite fylesystem on Windows using Activestate Perl 5.8.8 and try to set $File::Find::name ; therefore I am not stat - the name of the file obtained from scanning a text file requiring the removal of chomp -ing or a new line. I was unable to get the file modification time, mtime at:

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

so try

 -s $File::Find::name 

gives me an error:

Failed stat for file name containing new line

Typical file name found: F01-01-10 Num 0-00000.pdf, but I get the same error even when renaming to E02.pdf

+4
source share
4 answers

According to perldiag , if a file operation fails and the file name contains a newline, the warning "Failed to file name containing a new line" will be emitted.

It is assumed that, as you say, the file name comes from standard input or similar, and the user forgot chomp new line. You might want to pass the string through chomp to make sure it works.

There is some evidence that &CORE::stat mtime may be violated by some combination of OS patchlevel and versions of ActiveState Perl - the proposed solution is to use the File :: stat module:

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

... you may find the representation of the File :: stat object more convenient than the list returned by CORE::stat .

+11
source

Even when I tried to delete the folder, I got the same error. I used chomp before using the rmtree command. This solved my problem.

0
source

In the same problem, my script problem arose, and I found that my error was that when I created the file, I marked the stamp date to the end and forgot to rewrite my $ DATE variable before adding it to the file name.

0
source

Yes, I just stumbled upon it myself using a manually created scanner. I scratched my head a bit until I realized that I included the time / date stamp in the file name. Chomp date and voila command, problem solved.

0
source

Source: https://habr.com/ru/post/1307127/


All Articles