sub pathtrim { my($path)=@_; return undef if($path eq '/'); $path =~ s#/[^/]+$#/#; $path =~ s#(/[^/]*)/+$#$1#; return $path; }