in reply to Re^2: using chdir($variable_name) to change directory
in thread using chdir($variable_name) to change directory
Instead of $1, use $! inside your error messages, and you'll get a more useful error message. If you want a more descriptive error message, add use diagnostics; to the beginning of your program. You may also want to put quotes around the input variable name inside your print statement so you can see if you've properly removed any extra whitespace from the path.
I also use indentation to clarify my code, so I've put my suggestions in your program to come up with:
use diagnostics; open(LIST,"small.txt") or die "Can't open small.txt: $!"; @arr= <LIST>; for($i = 0; $i < @arr; $i++) { chomp($arr[$i]); print "path read from file = '$arr[$i]'\n"; #it displays => ms_qu/the/path/written/in/file (fine till here +but it shud go to this place when i use chdir) chdir $arr[$i] or die "Can't change directory: $!"; print "After chdir, cwd is = "; system("pwd"); }
I haven't tested it, though, so give it a try and see if the error messages give you the information you need to fix it.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|