Welcome to the world of escaping! :)

If you have an end delimiter and you want to allow this end delimiter to appear literally you need to escape it, hence \' => '

But if you're escaping, you're also needing an escape character, which has also to be escaped when used literally, hence \\ => \

And thats it, nothing else needed within the single quotes family of q{} with a free choice of end delimiters.

And now, if you think that perl sucks try emacs lisp, which only supports double quotes! In elisp regexes suffer from a ugly disease called slasheritis².

Luckily you can use heredocs, because there is no delimiter that need to be escaped. And if you don't like the newlines then chomp:

$foo = <<'__HERE__'; \\some.address.or.whatever\subdir\ __HERE__ chomp $foo; print ">", $foo ,"<"; # >\\some.address.or.whatever\subdir +\<

I suppose you don't wanna put multiple path in a long heredoc? ¹

So why don't you use a character like / as placeholder?

sub s2b { # slash to backslash (my $str = shift) =~ tr#/#\\#; return $str; } my $path = s2b '//some.address.or.whatever/subdir/';

Just don't blame Perl for M$ decision to use an escape character for separating paths. =)

Cheers Rolf

update

fixed code for s2b()

footnotes

¹) you could read them into a hash defined by preceded hash keys.

use Data::Dump; sub parsepath { my $str=shift; return split /\s+/,$str; } my %path = parsepath <<'__HERE__'; install \\some.address.or.whatever\subdir\ deinstall \\other.address.or.whatever\subdir\ __HERE__ dd \%path;

==>

{ deinstall => "\\\\other.address.or.whatever\\subdir\\", install => "\\\\some.address.or.whatever\\subdir\\", }

²) yes, it insults the eyes!!!


In reply to Re: Single Quotes - how to avoid any escape processing? by LanX
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.