perl chdir not working, not changing the directory -
my complete perl script
chdir ("/etc" or die "cannot change: $!\n"); print "\ncurrent directory $env{pwd} \n";
and getting output (not expected)
bash-3.2$ perl test.pl
current directory /home
p.s. /home
executing test.pl
you should move
or die
outside ofchdir(...)
, i.e.:chdir("/etc") or die "cannot change: $!\n";
with have currently, expression
"/etc" or die "cannot change: $!\n"
evaluated first. result"/etc"
,die()
never gets executed.or die()
should "applied to"chdir()
call, not argument.do
print(cwd);
print current working directory. don't forgetuse cwd;
use cwd; chdir("/etc") or die "cannot change: $!\n"; print(cwd);
Comments
Post a Comment