in reply to Re: Testing for a directory handle
in thread Testing for a directory handle

If you attempt to use telldir on an invalid directory handle, you'll get a "telldir() attempted on invalid dirhandle" warning

Also, telldir returns undef in such a case, so I'm thinking we could alternatively just test for definedness:
C:\_32>perl -le "open D, '<','test.txt' or die $!; print 'dir' if defi +ned telldir D; print 'DONE';" DONE C:\_32>perl -le "opendir D, 'comp' or die $!; print 'dir' if defined t +elldir D; print 'DONE';" dir DONE
Of course, if it turns out that telldir was given something other than a handle, then it's a fatal error:
C:\_32>perl -le "open D, '<','test.txt' or die $!; print 'dir' if defi +ned telldir $x; print 'DONE';" Bad symbol for dirhandle at -e line 1.
So that scenario would need to be avoided.

On *nix machines it shows the "." and ".." entries

Yes, it's the same on Windows.

Cheers,
Rob

Replies are listed 'Best First'.
Re^3: Testing for a directory handle
by kcott (Archbishop) on Jan 30, 2018 at 03:48 UTC
    "Yes, it's the same on Windows."

    Thanks for that. I had a feeling it might have been the same but wasn't sure. It's been many years since I've written any code to interact with a MSWin filesystem.

    — Ken