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
In reply to Re: Surprising behavior of Cwd module on Unix with symlinks
by ikegami
in thread Surprising behavior of Cwd module on Unix with symlinks
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |