Keep It Simple, Stupid | |
PerlMonks |
Trimming Paths with regexesby TGI (Parson) |
on Aug 30, 2001 at 01:08 UTC ( [id://108903]=perlquestion: print w/replies, xml ) | Need Help?? |
TGI has asked for the wisdom of the Perl Monks concerning the following question: As part of a project I'm working on, I need to play with a path-like data structure. It comes in the form '/foo/bar/baz'. I need to check the full path, then '/foo/bar', then '/foo' and finally '/'. So I've put together a do {} while loop that terminates when the path variable is length 0. I'm using a regex to trim the path:
I keep futzing with the regex and can't come up with something that works. I keep failing to get '/' processed. Once again, here's the transformation I'm looking for: '/foo/bar'-> '/foo' '/foo' ----> '/' '/' -------> ''
Back to
Seekers of Perl Wisdom
|
|