[Israel.pm] abs_path vs. rel2abs

Mikhael Goikhman migo at homemail.com
Thu Feb 10 15:56:57 PST 2005

On 10 Feb 2005 16:59:16 -0500, Offer Kaye wrote:
> On Thu, 10 Feb 2005 21:23:13 +0200, Yuval Yaari wrote:
> > rel2abs can get a 2nd argument - base path (and uses cwd as default).
> > The 2nd argument is also converted using rel2base.
> > 
> > Another thing (citing the docs for rel2base, $path is the first argument):
> > <CITE>
> > If $path is absolute, it is cleaned up and returned using "canonpath()".
> > </CITE>
> > 
> > So as minor as it may be, there is a difference.
> Okay, but why doesn't rel2abs remove "../" stuff from the path, the
> way abs_path does?

I am not familar at all with File::Spec, but strictly speaking, reducing
relative paths is impossible in the general case, on unix at least.

You can minimize the absolute path containing "../" by doing "cd ..; pwd"
(I suppose File::Spec does not do this to be faster), but if you only
have relative path at hand, you have no idea about symbolic links or some
kinds of auto-mount-points that may be present in the real absolute path.

For example, /usr/local is a symlink to /var/local, and you have relative
path "local/../tmp". If you reduce it to just "tmp", as you suggest, and
apply it to "/usr" then you get /usr/tmp instead of the correct /var/tmp.
These are two different directories. So, you can't reduce relative paths
by simply removing "../" stuff from them.

Read about $Bin and $RealBin in `perldoc FindBin` for a similar point.


perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'

More information about the Perl mailing list