in reply to Re^3: Cleaning up a path
in thread Cleaning up a path

Correct, but I did not dare asking for some solution which could be valid for relative filenames: this would be some kind of sphere reading!

Just before you reply (I can hear your breath on my neck!), I want to admit that it also fails miserably with this valid, absolute path:

/.. -> <- still broken
I'm understanding proper testing these days...

Flavio (perl -e "print(scalar(reverse('ti.xittelop@oivalf')))")

Don't fool yourself.

Replies are listed 'Best First'.
Re^5: Cleaning up a path
by ikegami (Patriarch) on Apr 13, 2005 at 18:28 UTC

    I fixed your code for all cases except '/..' (which returns '.'):

    sub remove_dot_dot_frodo72 { my $path = File::Spec::Unix->canonpath($_[0]); my @true; /^\.\./ && @true ? pop(@true) : push(@true, $_) # <- Added to cond foreach File::Spec::Unix->splitdir($path); $path = File::Spec::Unix->catdir(@true); return length($path) ? $path : '.'; # <- Added. }