Well, I want the trailing slash. It's needed in the context of my algorithm, currently. catdir on *nix does not create a trailing slash. I can recode my algorithm pretty easily but I thought it was weird that the same method produces two separate results.
| [reply] |
If you improve your algorithm to process directories as arrays of name components instead of copying back to strings, it will not be a problem any more and your algorithm should be faster, too.
As for the odd behavior, I suspect that it was needed for portability to some oddball half-broken commercial Unix back in the 5.005 era. :-)
| [reply] |
Yeah, I thought about processing an array but I would still have to use File::Spec to split the file path and I could just feel it in my bones that there would still be some weird cross-platform issue lingering and I just want to go to bed. So I just did letter-by-letter comparison. Speeding it up will have be a task for another day.
| [reply] |
Conceptually directory structures are trees, and paths are lists of nodes that represent traversal(1). When you think of things that way instead of strings with slashes, life becomes easier, and common tools tend to just work. Pushing to the boundaries of your application as much representational decoration as possible, and internally working with more native data structure types is a principal that doesn't only apply to data serialization formats, it also applies to filesystem paths.
Your algorithm should be working with lists of directory names and file names, and converting to slash-delimited strings at the ingress and egress boundaries.
(1) Actually many file systems are directed acyclic graphs, thanks to concepts such as hard linking, but conceptually we can treat them like heirarchical data structures, keeping in mind that it's possible for a node in the tree to point to any other node anywhere else in the tree. ...so the tree concept does sort of break down, but is a useful white lie.
| [reply] |