in reply to Re: Collapsing paths
in thread Collapsing paths

canonpath in File::Spec seems to do the trick.

Did you try it out?

#!/usr/bin/perl use File::Spec; print File::Spec->canonpath("foo/../bar/../baz/")."\n";

Output:

foo/../bar/../baz

I guess not. Did you read the docs? Quote:

Note that this does *not* collapse x/../y sections into y. This is by design.
I guess not.

All dogma is stupid.

Replies are listed 'Best First'.
Re^3: Collapsing paths
by ikegami (Patriarch) on Dec 05, 2007 at 16:57 UTC
    Depends on your system.
    use File::Spec; print File::Spec->canonpath("foo/../bar/../baz/")."\n";
    \baz

    On system without symlinks, canonpath collapses x/../y (although not always correctly, as shown above).

    Update: Technically, NTFS does have symlinks, but most software act as if they don't exist, including File::Spec.

Re^3: Collapsing paths
by lodin (Hermit) on Dec 05, 2007 at 20:34 UTC

    Did you try it out?

    Yes I did. That's why I wrote "seems". I didn't know the behaviour was platform dependant. The documentation for File::Spec is contradicting the File::Spec::Win32 documentation which specifically says "foo/../bar" will become "bar".

    lodin