When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd
returns still the same directory. Should that be so?
I tried this, because in the documentation to chdir I found:
"On systems that support fchdir, you might pass a file handle or directory handle as argument. On systems that don't support fchdir, passing handles produces a fatal error at run time."
Given later:
#!/usr/bin/perl -w
use 5.010;
use strict;
use Cwd;
say cwd(); # /home/mm
open( my $fh, '>', '/home/mm/Documents/foto.jpg' ) or die $!;
say chdir $fh; # 0
say cwd(); # /home/mm
I thought that this would maybe chdir to the directory of the file - but no DWIM for me here.
It also says
meaning that your call to
chdir
failed. Check the$!
variable for a clue about what happened. Since you didn't get a fatal runtime error, you don't have to worry about that last paragraph aboutfchdir
.Running a couple of tests, I see
chdir FILEHANDLE
works whenFILEHANDLE
refers to a directory, but not to a regular file. Hope that helps: