Returns the path shortened and handles paths with //'s together like ////usr/bin correctly. Returns undef in the special case of the root path. Does not handle relative paths
sub pathtrim { my($path)=@_; return undef if($path eq '/'); $path =~ s#/[^/]+$#/#; $path =~ s#(/[^/]*)/+$#$1#; return $path; }
In reply to Re: Trimming Paths with regexes
by dga
in thread Trimming Paths with regexes
by TGI
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |