in reply to Symbolic Link

I don't know how to get perl to do that, but I can with bash. How about a kludge like

perl -e 'system "cd -P ./cs_envs && echo \$PWD";'

which resolves the symbolic link, and this

perl -e 'system "cd -L ./cs_envs && echo \$PWD";

which doesn't.

BTW: ./cs_envs is a symlink in my home directory. In the first one is shows the real (resolved) path, and the second one it shows the logical (unresolved) path.

- doug

Replies are listed 'Best First'.
Re^2: Symbolic Link
by Anonymous Monk on May 21, 2009 at 05:29 UTC
    sub utilGetAbsoluteFileName{ my $fileName = shift; $fileName =~ s/\/+/\//g; if(! -e $fileName){ return $fileName; } my $dir = getcwd; if ($fileName !~ /^\//){ $fileName = $dir."\/".$fileName; } my @targetArr = (); my @fileArray = split "\/", $fileName; for (my $index=0; $index<@fileArray; $index++){ next if($fileArray$index eq "\."); if($fileArray$index eq "\.\."){ pop @targetArr; }else{ push @targetArr, $fileArray$index; } } my $absFileName = join "/", @targetArr; $absFileName =~ s/\/+/\//g; return $absFileName; } I have written this API which calculates the absolute path for any filename in unix. It takes care of "../../" and "./". Please tell if i have missed any case. Thanks