This doesn't work since the \' gets escaped and I end up effectively with a missing ' So, tried to escape the \ with the following...$PathOnly = "c:\Dir1\Dir2\Dir3"; @SubDirs = split('\', $PathOnly);
But that also has an error "trailing \ in regex" As does the following...@SubDirs = split('\\', $PathOnly);
I even tried the following...@SubDirs = split("\\", $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 $SplitAt = "\\\\"; my @SubDirs = split($SplitAt, $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, Stevemy @SubDirs = split("\\\\", $PathOnly);
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |