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').'/';

In reply to Re^4: Directory Separator (none) by Anonymous Monk
in thread Directory Separator by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.