in reply to Surprising behavior of Cwd module on Unix with symlinks
Cwd's getcwd simply returns what the system provides. Your shell is actually tracking the work directory separately from the system, but it provides it via $ENV{PWD}. You can use it safely as follows:
use Cwd qw( getcwd ); sub my_getcwd { use Cwd qw( ); sub getcwd { my $cwd = Cwd::getcwd(); if (exists($ENV{PWD}) && $ENV{PWD} ne $cwd) { my $e = my ($e_dev, $e_node) = stat($ENV{PWD}); my $c = my ($c_dev, $c_node) = stat($cwd); if ($e && $c && $e_dev == $c_dev && $e_node == $c_node) { $cwd = $ENV{PWD}; } } return $cwd; } print Cwd::getcwd(), "\n"; print getcwd(), "\n";
/tmp/ikegami /home/ikegami/tmp
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Surprising behavior of Cwd module on Unix with symlinks
by DrHyde (Prior) on Feb 08, 2011 at 10:53 UTC | |
by ikegami (Patriarch) on Feb 08, 2011 at 16:15 UTC | |
by DrHyde (Prior) on Feb 09, 2011 at 11:03 UTC | |
by ikegami (Patriarch) on Feb 09, 2011 at 15:22 UTC |