in reply to Trimming Paths with regexes

Just to show that it's not too complicated with a regex:

do { # your stuff here print "\t\t$path\n"; } while $path =~ s#(?:(^/)|/)[^/]+$#$1?$1:''#e;
You can use a subroutine as well, then the regex is pretty simple if you handle the special case beforehand:
sub pathtrim { my ($path) = @_; return '/' if ($path =~ m#^/[^/]+$/); $path =~ s#/[^/]+$##; return $path; }

Update: Fixed small bug in the subroutine.

-- Hofmator