Part of the difficulty might be that even inside single quotes (or quoting construct as here) the backslash is a tricky customer.
knoppix@Microknoppix:~$ perl -E ' > $bp = q{\\dirA\dirB\dirC}; > say $bp;' \dirA\dirB\dirC knoppix@Microknoppix:~$ perl -E ' $bp = q{\\\dirA\dirB\dirC}; say $bp;' \\dirA\dirB\dirC knoppix@Microknoppix:~$ perl -E ' $bp = q{\\\\dirA\dirB\dirC}; say $bp;' \\dirA\dirB\dirC knoppix@Microknoppix:~$ perl -E ' $bp = q{\\\\dirA\\dirB\\dirC}; say $bp;' \\dirA\dirB\dirC knoppix@Microknoppix:~$
Riales has given you the best method but, just to show another way, you could split the paths rather than substituting the backslashes and shift off the common elements before joining what's left to get the relative path.
knoppix@Microknoppix:~$ perl -E ' > $bp = q{\\\\dirA\\dirB\\dirC}; > say $bp; > $cp = q{\\\\dirA\\dirB\\dirC\\dirD\\dirE}; > say $cp; > @bpParts = split m{\\}, $bp; > @cpParts = split m{\\}, $cp; > do { shift @bpParts; shift @cpParts } while @bpParts; > $rp = join q{\\}, @cpParts; > say $rp;' \\dirA\dirB\dirC \\dirA\dirB\dirC\dirD\dirE dirD\dirE knoppix@Microknoppix:~$
I hope this is helpful.
Cheers,
JohnGG
In reply to Re: Help with Regular Expressions
by johngg
in thread Help with Regular Expressions
by FFSparky
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |