in reply to Trimming Paths with regexes
Just to show that it's not too complicated with a regex:
You can use a subroutine as well, then the regex is pretty simple if you handle the special case beforehand:do { # your stuff here print "\t\t$path\n"; } while $path =~ s#(?:(^/)|/)[^/]+$#$1?$1:''#e;
sub pathtrim { my ($path) = @_; return '/' if ($path =~ m#^/[^/]+$/); $path =~ s#/[^/]+$##; return $path; }
Update: Fixed small bug in the subroutine.
-- Hofmator
|
|---|