It has been a long time since I've had to write a Perl program that had to support an OS other than Linux/Unix/POSIX, MS Windows and Mac OSX.

Internally, MS Windows accepts / as a path separater. It is cmd.exe that has a problem because it treats / as the option introducer. So, c:/path/to/file or even c:\path\to/file are valid.

Of course, Linux/etc and Mac OSX don't use volume designaters ("drive letters"), so would try to treat "c:" as a directory in the current directory, but, so far, in the Perl programs I've written, the only source of volume designaters is from user input (either directly or through a file dialog box).

In the rare case I have to start cmd.exe from Perl, I have used File::Spec::canonpath to insure the file path is acceptable.

Otherwise, I usually treat file paths as POSIX style and have no problems.

For example, to split a path, I just use

@dirs = split qr{[\\/]}, $path; $file = pop @dirs unless -d $path;

And to assemble a path

$path = '/' . join '/', @dirs, ($file // '');

Mostly, I don't care about the volume. If I need it, it's in $dirs[0].


In reply to Re^2: open file error by RonW
in thread open file error by t-rex

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.