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

> Linux lets you open a directory as a file without an error, but then you can't do anything with it.

You can do something.

open my $d, '<', '..' or die $!; # Doesn't die. say -e $d; # 1. say -d $d; # 1. say -f $d; # Nothing. chdir $d or die $!; # Switches to the parent directory ( +read "perldoc -f chdir").

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
chdir FILEHANDLE
by parv (Parson) on Jul 10, 2024 at 21:47 UTC
    From chdir function ...
    ... chdir FILEHANDLE chdir DIRHANDLE ... On systems that support fchdir(2), you may pass a filehandle or dire +ctory handle as the argument. On systems that don't support fchdir(2) +, passing handles raises an exception.

    ... fchdir(2) ought to be present on POSIX-conforming systems, from "fchdir(2)" manual page of FreeBSD 14 ...

    ... STANDARDS The chdir() system call is expected to conform to IEEE Std 1003.1 +-1990 (“POSIX.1”). HISTORY The chdir() system call appeared in Version 1 AT&T UNIX. The fchdir( +) system call appeared in 4.2BSD.