Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
When I run this, I get: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; }
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: "readdir() attempted on invalid dirhandle" error?
by Paladin (Vicar) on Jul 10, 2024 at 20:05 UTC | |
|
Re: "readdir() attempted on invalid dirhandle" error?
by NERDVANA (Priest) on Jul 10, 2024 at 20:14 UTC | |
by choroba (Cardinal) on Jul 10, 2024 at 21:35 UTC | |
by parv (Parson) on Jul 10, 2024 at 21:47 UTC | |
by parv (Parson) on Jul 10, 2024 at 21:12 UTC | |
by Anonymous Monk on Jul 10, 2024 at 20:39 UTC | |
by hv (Prior) on Jul 10, 2024 at 22:30 UTC | |
by ikegami (Patriarch) on Jul 11, 2024 at 13:45 UTC | |
by ikegami (Patriarch) on Jul 11, 2024 at 13:56 UTC |