Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I have sometimes found myself looking for a way to create pathnames with a trailing slash ("foo/bar/") and/or a "./" prefix ("./foo/bar") that is a little "safer" (platform-independent, etc.) than "./$path/". To name just a few examples of when this is needed: The behavior of rsync sometimes depends on whether a pathname has a trailing slash or not. In some cases, the "./" prefix makes a difference to find. Often file patterns, such as in gitignore, will match only directories if there is a trailing slash on the name.
I usually use File::Spec for all path manipulation, but that and Path::Class won't work because they always try to "clean up" the path they return. In Linux, File::Spec->catdir(".","foo","") simply returns "foo". Using File::Spec->catfile(".","foo","") only returns "foo/" and also feels a little hackish.
It would be nice if there were two functions that provided the "./" prefix and trailing separator. I have so far only found File::Util's SL constant which provides the directory separator, but that's only half the battle and I'd love to find a way to solve this using a core module, if at all possible.
I feel like I'm missing something. Any wisdom you may have on this topic would be greatly appreciated!
P.S. From what I've read there are some systems (VMS?) where the concept of a directory separator is not as simple as doing $path1 . $DIRSEP . $path2, but for starters a solution for the not-so-compilcated cases would be nice.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Directory Separator (none)
by tye (Sage) on May 28, 2013 at 16:48 UTC | |
by vsespb (Chaplain) on May 28, 2013 at 17:10 UTC | |
by tye (Sage) on May 28, 2013 at 23:03 UTC | |
by vsespb (Chaplain) on May 28, 2013 at 23:39 UTC | |
by Anonymous Monk on May 29, 2013 at 15:36 UTC | |
|
Re: Directory Separator
by vsespb (Chaplain) on May 28, 2013 at 16:44 UTC |