in reply to Simple Path Cleanup

Play around with Path::Class-

perl -MPath::Class -le 'print file(+shift)->cleanup' [path]

For example-

perl -MPath::Class -le 'print file(+shift)->cleanup' /foo//baz/./foo.t +xt /foo/baz/foo.txt

It has become one of my favorite families of modules.

Replies are listed 'Best First'.
Re^2: Simple Path Cleanup
by almut (Canon) on May 10, 2009 at 09:00 UTC

    It sounds to me (I could be misunderstanding, though) like the OP wants to avoid removing some major directory. So lets say the input path is something like

    /home/whoever/tmp/foo/mydir

    where mydir is a symlink to /usr/local or some such, then Path::Class's cleanup would leave it as is, and /usr/local would get removed, even though the OP checks $path !~ m#^/usr/local# (presuming appropriate permissions, of course).  AFAIK, Path::Class doesn't handle symlinks, whereas Cwd's realpath would.

      Thank you, that actually jogged me into remembering to check link status before running remove_path. That would've been a pretty big mistake.

      You're right. Good clarification.