Perl 嵌套的;如果是;,缺少右曲括号或方括号
我目前有以下情况:Perl 嵌套的;如果是;,缺少右曲括号或方括号,perl,if-statement,Perl,If Statement,我目前有以下情况: elsif ($line =~ /^(\s*)(if|elif|else)\s*(.+)*\s*:\s*$/) { # Multiline If # Print the If/Elif condition if ($2 eq "if"){ print "$1$2 ($3){\n"; } elsif ($2 eq "elif"){ print "$1elsif ($3){\n"; } el
elsif ($line =~ /^(\s*)(if|elif|else)\s*(.+)*\s*:\s*$/) {
# Multiline If
# Print the If/Elif condition
if ($2 eq "if"){
print "$1$2 ($3){\n";
}
elsif ($2 eq "elif"){
print "$1elsif ($3){\n";
}
elsif ($2 eq "else"){
print "$1$2 $3{\n";
}
# Add the space before the word "if"/"elif"/"else" to the stack
push(@indentation_stack, $1);
}
我得到了声明的错误,但我不知道为什么。在最后的elsif
中,如果在print
语句中的{
之前添加\
,则代码不会生成错误
即:
有人能给我解释一下为什么会这样吗
感谢您的帮助!很棘手!问题是以下是哈希查找的开始:
$3{
你想要相当于
$3 . "{"
可以写成
"${3}{"
在这种情况下,以下操作有效,因为
\
不可能是该变量的一部分:
"$3\{"
但这一技巧并不总是被使用。例如,考虑
$foo . "bar"
如果你尝试
"$foo\bar"
你会发现你得到了
$foo . chr(0x08) . "ar"
因为“\b”
返回“bell”字符。这就给您留下了
"${foo}bar"
"${foo}bar"