in reply to Re^3: Directory Separator (none)
in thread Directory Separator

Thank you vsespb and tye for your thoughts.

I agree with tye that the arguments for stripping the trailing slash as stated in the catdir documentation are weak. But, changing that method would certainly break a lot of existing code, which is why I was thinking of a new method to do this.

While I'm beginning to think both of you are right (just go with "/" as the directory separator for the various reasons you name), it still bugs me a little. Maybe this will demonstrate better:

use Path::Class; # maybe $DIR is read from a configuration file or passed in from anoth +er tool my $d = dir($DIR); $d = $d->parent->subdir("bar"); # one "right" way to do path manipulat +ion my $p = $d=~/\/$/ ? "$d" : "$d/";

Unless you're 100% sure that this system's path separator is "/", doesn't that last line feel like a bad practice? I'm still feeling some cognitive dissonance about this :-)

Maybe this is a solution? Here, we know that the separator will be a slash and that catdir's result won't have a trailing one.

require File::Spec::Unix; my $x = File::Spec::Unix->catdir('foo','bar').'/';