in reply to Re: Absolute pathnames from relative?
in thread Absolute pathnames from relative?

Thanks Matt, I was guessing it had something to do with symlinks but hadn't put all the pieces together. Interestingly (or not) the colleague who originally asked me the question was working on Win32 which doesn't do symlinks but even on that platform, File::Spec::Win32 still leaves the '..' parts in place.

The no_upwards() method doesn't quite seem to do what I need either (I had tried it before I posted originally). It takes a list of pathname components and all it does is eliminate the '.' and '..' components (ie: it doesn't remove the component before the '..') - I'm not sure when that would be useful. Even it it did what I wanted, by the time I'd called splitdir() to provide the right inputs and then catdir() to reassemble the output, the end result would hardly be a clear and concise piece of code.

I guess I'll stick with my URI solution. Thanks again.

Replies are listed 'Best First'.
Re^3: Absolute pathnames from relative?
by mojotoad (Monsignor) on Jan 22, 2003 at 18:08 UTC
    The no_upwards() behavior sounds like a bug, in my mind. It makes no sense to eliminate '..' without considering the consequences.

    I neglected to mention in my initial writeup that soft links are not the only time this arises -- mount points will do it as well. Mounted disks might be local or remote -- they might even be on different operating systems. Same dynamic, though: system_a:/server_disk/home/hubba could be mounted on system_b:/home/hubba. Typically this depends on the NFS implementation (or whatever the remote disk sharing protocol might be).

    rob_au is correct that the abs_path() method of Cwd is the best way to perform this trick using a physical system check. abs_path() itself, last time I checked, is based on File::Spec and the Cwd methods cwd() and pwd() routines. There is an analogous fast_abs_path() that "does the right thing" that you expect, without a physical check. Entirely reliable, however, if you expect to be on a homogenous system.

    Matt