Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: "readdir() attempted on invalid dirhandle" error?

by Anonymous Monk
on Jul 10, 2024 at 20:39 UTC ( [id://11160530]=note: print w/replies, xml ) Need Help??


in reply to Re: "readdir() attempted on invalid dirhandle" error?
in thread "readdir() attempted on invalid dirhandle" error?

(OP here) God, I knew it was something stupid and obvious like that! But why on earth would Perl not return an error when opening (not opendiring) a directory? Aargh. Thank you (both) for this. This task doesn't require any fancy tree-walking, the directory will just be a flat folder with files in it, so this is pretty much all I need for this purpose.

Replies are listed 'Best First'.
Re^3: "readdir() attempted on invalid dirhandle" error?
by hv (Prior) on Jul 10, 2024 at 22:30 UTC

    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.

      File handles and directory handles are stored in different slots of the glob. From Perl's perspective, the problem isn't that the provided handle is the wrong kinda of handle; the problem is that the provided glob didn't contain a dir handle.

        Except open and opendir doesn't let you use both slots anymore.

        5.10: Warns when warnings enabled.
        5.12: Warns by default.
        5.26: "This will be a fatal error in Perl 5.28" to the warning.
        5.28: Fatal.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11160530]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-09-17 09:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (22 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.