in reply to cleaning up absolute path without resolving symlinks

I've used this routine in the past. It seems to work with your data.

use strict; use warnings; my @paths = qw{ /self/xplanatori /usr/lib/perl5/../../ /home/fake4/../fake/ /resolve/me/../right/ /./resolve////me/../right/. /../.././usr/././. /../.././////././. /..... .///../}; print qq{@{[cleanPath($_)]}\n} for @paths; # --------- sub cleanPath # --------- { my $absPath = shift; return $absPath if $absPath =~ m{^/$}; my @elems = split m{/}, $absPath; my $ptr = 1; while($ptr <= $#elems) { if($elems[$ptr] eq q{}) { splice @elems, $ptr, 1; } elsif($elems[$ptr] eq q{.}) { splice @elems, $ptr, 1; } elsif($elems[$ptr] eq q{..}) { if($ptr < 2) { splice @elems, $ptr, 1; } else { $ptr--; splice @elems, $ptr, 2; } } else { $ptr++; } } return $#elems ? join q{/}, @elems : q{/}; }

Here's the output.

/self/xplanatori /usr /home/fake /resolve/right /resolve/right /usr / /..... /

I hope this is of interest.

Cheers,

JohnGG