This is going to be a lot more answer than you are looking for but as you are in a cross-platform situation I thought I'd share what I have found to be a very re-usable format. I'm in a situation where CPAN is difficult to utilize effectively in our organization, so I created a module I called OSify.pm. In it I created common OS commands OSrecursive copy, OSmkdir, etc and centralized their logic, It has made it so I can code for DOS, linux, and Solaris with the same commands easily, and can be quickly extended to other OS's as required. The following is just the OSPath() that takes care of the delimiter issue, but using the general approach it's easy to adapt to any given command.

sub OSpath { $_ = $_[0]; debug( "Recieved path as\n $_\n", 0 ); if ( $^O =~ /mswin/i ) { # Everywhere you find a forward back slash replace it with # two backslashes if ( /(\/|\\\w)/ ) { s/(\/|\\)/\\\\/g; } # Incase we've created four backslashes in a row # reduceit back to one if ( /(\\)(\\)(\\)(\\)/ ) { s/\\\\\\\\/\\\\/g; } # Have to make sure there is only 1 slash after a drive letter if ( /(\:\\\\).*/ ) { s/$1/\:\\/; } } elsif ( $^O =~ /solaris/i ) { s/\\/\//g; if ( $_ =~ /.*\/(.*\s.*)\/.*/ ) { my $spacedDir = $1; unless ( $spacedDir =~ /"/ ) { $_ =~ s/$1/"$spacedDir"/g; } } } else { print "Platform $^O is not currently supported\n"; } debug( "Returning path as\n $_\n", 0 ); return $_; }

In reply to Re: Platform independant directory separator by coreolyn
in thread Platform independant directory separator by jaa

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.