Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Trimming Paths with regexes

by jryan (Vicar)
on Aug 30, 2001 at 01:21 UTC ( [id://108908]=note: print w/replies, xml ) Need Help??


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 :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://108908]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2025-07-15 19:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.