in reply to How do I change directory to root directory

I'm a little unclear as to what is wrong so I'll take a few stabs :)

Your code will successfuly change to ./mydirectory as long as the script is executed in the directory that contains ./mydirectory.

If you need to change to that directory from anywhere on the filesystem you just need to use a full path. i.e.

#!/usr/bin/perl use strict; my $dir = "/foo/bar/mydirectory"; chdir($dir) || die "Whoops: $!\n";

When the script exits you will still be in the directory you started in. The shell forks and runs your perl script, the script changes directory and exits. Nowhere in this process does the child process change the CWD of the parent. I don't actually believe that thisis possible.

It's kinda cheesy but if you want to run the script and be at the directory the script chdir'd to when it finishes you could run the chdir and then exec a shell. You would get a new shell to do with what you want. However, this would be a sub-shell of the one you started in.

Hope something in this rambling helps.