Although this is an old thread I think it aligns well with a current issue I have whilst processing Windows paths. I have spent the last hour scouring THE WEB and can't for the life of me find a clean solution to my issue. Basically what I want to do is split a path into a list of each sub directory, so in its simplest form I tried the following...
$PathOnly = "c:\Dir1\Dir2\Dir3"; @SubDirs = split('\', $PathOnly);
This doesn't work since the \' gets escaped and I end up effectively with a missing ' So, tried to escape the \ with the following...
@SubDirs = split('\\', $PathOnly);
But that also has an error "trailing \ in regex" As does the following...
@SubDirs = split("\\", $PathOnly);
I even tried the following...
my $SplitAt = "\\"; my @SubDirs = split($SplitAt, $PathOnly);
Whilst this doesn't have syntax errors, and $SplitAt seems to get theexpected "\" it fails on the execution of the split with the same "trailing \ in regex", just at execution time this time. Now... just for kicks and giggles I tried the following...
my $SplitAt = "\\\\"; my @SubDirs = split($SplitAt, $PathOnly);
BOOM !!! I get the correct result (I actually thought of this whilst typing the comment but figured the info might help someone at some point in time) So, then I tried the following...
my @SubDirs = split("\\\\", $PathOnly);
This also worked as I wanted. So, my original question has changed from "How do I split a Windows path on \ ?" to "Why does "\\\\" work in the split statement? I have been working with Perl on and off for about 20 years but I am by no means an expert, but this conundrum completely confuses me. BR, Steve

In reply to Re: Single Quotes - how to avoid any escape processing? by SteveDC
in thread Single Quotes - how to avoid any escape processing? by temporal

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.