I'm tearing my hair out over what should be a Perl 101 issue, and just can't tell what's going on. I have a script that processes some stuff, and then sends a directory over to a separate module for further processing. The module is unable to read the directory, and I don't know why. The code (so far!) is incredibly simple:
sub process_directory {
my ($self, $dir) = @_;
print "TESTING: dir is [$dir]\n";
open my $dh, $dir or die "Could not open dir [$dir] for reading: $
+!\n";
my @files = readdir $dh;
print "FILES: @files\n";
closedir $dh;
}
When I run this, I get:
TESTING: dir is [/tmp/testdirectory]
readdir() attempted on invalid dirhandle $dh at /path/to/MyModel.pm li
+ne 14.
FILES:
closedir() attempted on invalid dirhandle $dh at /path/to/MyModel.pm l
+ine 18.
/tmp/testdirectory exists, it's a directory, and the caller has permissions to read it.
I'm using strict and warnings. I don't get this--the open didn't fail; what's the problem here? I've searched for this, and the usual error is that people try reading a file as a directory or something like that; that's not the case here.