in reply to Trimming Paths with regexes
I had to deal with a similar situation one time. Instead of fiddling with a regex all day, I used split to split the path up, and then put it back together (minus the last part). It was similar to this:
my $oldpath = "/foo/bar/baz"; my @path = split(/\//, $oldpath); my $newpath = ""; for ($i=0; $i<(@path-1); $i++) { $newpath .= "/".$path[$i]; } print $newpath;
It might not be as cleany coded as a regex (or as cool looking!), but it gets the job done. Sometimes the simple solutions are the best :)
|
|---|