John W. Krahn wrote:
Chen Yue wrote:
I have a file containing UNIX-styled Path in each line. But the path is
simplified enough. Some of them has ".." and "." in the middle, such as
"/a/b/./c/../d". Now I want to simplify each Path according to Unix
tradition.
/a/b/./c/../d -> /a/b/d
The only way I could think out is to split the path and reconstruct
them in
reverse order. But I don't think it is a smart solution. Is there a quick
way to employ regexp or a library to fix this?
$ perl -le'$_ = q[/a/b/./c/../d]; print; s![^/]+/\.\./|\./!!g; print'
/a/b/./c/../d
/a/b/d
Or better:
$ perl -le'$_ = q[/a/b/./c/../d]; print; 1 while s![^/]+/\.\./!!; 1
while s!\./!!; print'
/a/b/./c/../d
/a/b/d
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/