如何才能打印包含双反斜杠\\
字符的字符串(单引号),而无需使Perl以某种方式将其插入单斜杠\
?我不想通过添加更多转义字符来更改字符串。如何防止Perl将双反斜杠解释为单反斜杠字符?
my $string1 = 'a\\\b';
print $string1; #prints 'a\b'
my $string1 = 'a\\\\b';
#I know I can alter the string to escape each backslash
#but I want to keep string as is.
print $string1; #prints 'a\\b'
#I can also use single-quoted here document
#but unfortunately this would make my code syntactically look horrible.
my $string1 = <<'EOF';
a\\b
EOF
print $string1; #prints a\\b, with newline that could be removed with chomp
让我猜...处理Windows文件路径? – Schwern
不,我将单引号字符串传递给子例程,这些字符串包含双反斜线。 – Omar
哦。你能举个例子吗?您不应该在单引号内部使用双引号。 “她说,”你不必在单引号中双引号。“”没关系。所以如果你想要插值但是不想用双引号来使用'qq []'。 – Schwern