But why on earth would Perl not return an error when opening (not opendiring) a directory?
As others have shown, there's nothing intrinsically invalid about open on a directory. However I think Perl is definitely capable of giving a more informative error message when you try to use a filehandle in a context that requires a directory handle. I'd recommend opening a github issue tagged as 'Wishlist' suggesting that there's an opportunity for improvement here.
Update: the issue now exists as #22394.
In reply to Re^3: "readdir() attempted on invalid dirhandle" error?
by hv
in thread "readdir() attempted on invalid dirhandle" error?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |