如何才能打印包含雙反斜槓\\
字符的字符串(單引號),而無需使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