in reply to Minimizing paths?

sub reduce_path ($) { # given a path which may contain multiple instances of .. # generate an absolute path my @path = split /\//, shift; my @new_path; while (scalar @path) { $_ = shift @path; if (/^\.\.$/o) { pop @new_path or croak "I can't recurse past my root\n"; } elsif (/^.$/o) { # do nothing. } else { push @new_path, $_; } } return join ('/', @new_path); } # usage: print reduce_path '/foo/bar/../baz', "\n"; print reduce_path '/foo/bar/../../baz', "\n"; print reduce_path 'foo/bar/baz/../', "\n";