yonyon100 yonyon100 - 8 months ago 51
Perl Question

open error - No such file or directory

I am using

to run through a directory tree and when I try to open the current file for reading I get
No such file or directory
. This happens with ALL files in the directory tree.

Here's the sub I use in the

sub {
if (-d) {
if (-f) {
my $file = ${File::Find::name};
open (my $IN, '<', '$file') or die "$!\n";
while (<$IN>) {
### Do some formatting.
close $IN;

It fails in the line:

open (my $IN, '<', '$file') or die "$!\n";

I thought it's a matter of links maybe, but even with
follow => 1
option I get this error.

By the way, without
the error I get is on the first file of the first directory I find and with it, the error is on the last file of the last directory (but in both cases, it's on the first file inspected by

Answer Source

Problem solved. Apparently, replacing the single quotes with double quotes in the open line, or even better, not using any quotes, did the trick. The string literal '$file' produces the string $file, and there's clearly no file with this name.