The module Cwd in standard distribution (AFAIK) comes to rescue
Use Cwd;
my $current_dir = cwd();
print "The current working directory is $current_dir\n";
Cwd works cross platform
HTH | [reply] [d/l] |
yes Cwd Works fine.
but it is very expensive and has to maintain the working directory all time.
So use it carefully and only when required.
xornand
| [reply] |
I've had problems with Cwd in the unix environment
whenever your process is non-root and is working in a
subdirectory of a directory that has the execute bit witout
the read bit set.
My understanding is that Cwd essentially just does a CD ..
until it gets to / and then CD's back to where it came from. But,
if it can not read every single directory on the way back to
/ it gets confused.
There is a way to get Cwd make a system call to /bin/pwd,
but if that's all the module is good for, then you might
as well just do something like this:
chomp ( my $dir = `/bin/pwd` );
There probably is some way to make Cwd always do the
right thing. If anybody knows what that is, I'd love to
know | [reply] [d/l] |
The special variable $0 contains the full path of the script including the script name.
If you knew the name of the script then to work out the directory the script is in you could use something like:
($cur_dir = $0) =~ s/$name_of_script//;
Rob | [reply] [d/l] |
If your just trying to make sure you know what the current directory is your could simply chdir("/some/known/dir"); at the top of your code. Else go with Cwd and unload it when your done with it. | [reply] [d/l] |
sorry about the ignorance but what do you mean by unloading Cwd?
Hotshot
| [reply] |
use Cwd;
Unload a module:
no Cwd;
[ ar0n -- want job (boston) ]
| [reply] [d/l] [select] |
use POSIX qw(getcwd);
my $curdir = getcwd();
--
Ilya Martynov
(http://martynov.org/)
| [reply] [d/l] |