如何修复 perl 语法错误“缺少右大括号或方括号"?使用 VIM 吗? [英] How do I fix the perl syntax error "missing right curly or square bracket" using VIM?

查看:246
本文介绍了如何修复 perl 语法错误“缺少右大括号或方括号"?使用 VIM 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编译(或执行)带有不匹配的数组大括号([ ]")或范围括号({ }")的 perl 程序会导致缺少右大括号或方括号"语法错误.Perl 经常将源代码报告为您的最后一行代码(at EOF"),这可能与实际丢失的部分相去甚远.

Compiling (or executing) a perl program with unmatched array braces ("[ ]") or scope brackets ("{ }") causes the "missing right curly or square bracket" syntax error. Perl often reports the source as your last code line ("at EOF"), which could be far removed from the actual missing piece.

perl 错误信息示例:

Example perl error message:

Missing right curly or square bracket at ./foo.pl line 100, at end of line
syntax error at ./foo.pl line 100, at EOF
Execution of ./foo.pl aborted due to compilation errors.

vi 或 Vi IMproved (VIM) 用户如何解决此错误消息?我添加了一些 VIM 增强的答案.请添加您自己的想法、做法或 vi 插件.

How do vi or Vi IMproved (VIM) users troubleshoot this error message? I've added an answer with some VIM enhancements. Please add your own ideas, practices, or vi plugins.

注意:原始问题与 VIM 版本一起发布,但未突出显示 perl 大括号和方括号.许多较新的版本都这样做;请参阅 vim.org 了解更多信息.

NOTE: Original question posted with VIM version that didn't highlight perl braces and brackets. Many newer versions do this; see vim.org for more info.

推荐答案

如何立即解决此错误:

  1. 在 VIM 中,选择一个开始的 {、[ 或 ( 符号.% 命令在匹配的 { }、[ ] 和 ( ) 对之间跳转.不匹配将跳转到意想不到的地方位置.

  1. In VIM, pick an opening {, [, or ( symbol. The % command jumps between matching { }, [ ], and ( ) pairs. Mismatches will jump to an unexpected location.

安装 perltidy,运行它,并寻找奇怪的缩进代码块.

Install perltidy, run it, and look for oddly indented code blocks.

如何防止将来出现错误:

How to prevent future errors:

  1. StackOverflow 问题 719476 显示如何修改大括号/方括号的 VIM 大括号/方括号语法着色.(有些版本默认不这样做.)

  1. StackOverflow question 719476 shows how to modify VIM brace/bracket syntax coloring for braces/brackets. (Some versions don't do this by default.)

Karl Guertin 的 AutoClose 插件 自动匹配 [,(, {, ", ' 键入时的符号.

Karl Guertin's AutoClose plugin auto-matches [, (, {, ", ' symbols when typed.

perltidy 脚本重新格式化 perl 以提高可读性,这可能会暴露不匹配的符号.

perltidy script reformats perl for readability, which can expose mismatched symbols.

用户付费书呆子说:使用perltidy 在带有 nmap."

User a paid nerd said: "Use perltidy within VIM editor with nmap."

nmap \g mt:%!perltidy't

使用一致的 {} 匹配缩进(一般提示,并非针对此 perl 错误).

Use consistent {} matching indentation (general tip, not specific to this perl error).

sub foo {
...
}

sub bar
{
...
}

这篇关于如何修复 perl 语法错误“缺少右大括号或方括号"?使用 VIM 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆