in reply to Single Quotes - how to avoid any escape processing?
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
fixed code for s2b()
¹) 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!!!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Single Quotes - how to avoid any escape processing?
by smls (Friar) on Jan 31, 2013 at 21:38 UTC | |
by LanX (Saint) on Jan 31, 2013 at 21:59 UTC | |
by smls (Friar) on Jan 31, 2013 at 22:57 UTC | |
by temporal (Pilgrim) on Jan 31, 2013 at 22:55 UTC |