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

  1. you should move or die outside of chdir(...), 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.

  2. do print(cwd); print current working directory. don't forget use cwd;


use cwd;  chdir("/etc") or die "cannot change: $!\n"; print(cwd); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -