Perl语法错误,但我一辈子都找不到它
这个错误让我很生气。我在这些行附近看不到任何有括号错误或缺少括号的内容。有人帮我一下吗?这是我的第一篇文章,如果格式不对,请原谅;我想我做对了。
编辑:第 87 行,');'错误,是这一行: select(SEXTANT_DAEMON_LOG);
syntax error at -edited- line 87, near ");"
syntax error at -edited- line 92, near "if"
syntax error at -edited- line 99, near "if"
Unmatched right curly bracket at -edited- line 102, at end of line
syntax error at -edited- line 102, near "}"
syntax error at -edited- line 109, near "}"
syntax error at -edited- line 120, near ");"
BEGIN not safe after errors--compilation aborted at -edited- line 122.
这是错误附近的代码(此处为完整代码):
$MAIN_DBH = getConnection('Main');
$fs_logfile = getCSConfigValue($MAIN_DBH, 'Log', 'Sextant Update Daemon') or die "pid$$[" . localtime(time()) . "] Main dbh error: " . DBI::errstr;
open(SEXTANT_DAEMON_LOG, '>>', $fs_logfile) or die "pid$$[" . localtime(time()) . "] unable to open log file '$fs_logfile'\n";
$tmp = select(SEXTANT_DAEMON_LOG);
$| = 1;
select(SEXTANT_DAEMON_LOG);
This error is angering me. I can't see anything near those lines with a parenthesis error or missing brackets. Someone give me a hand? This is my first post, forgive me if the formatting is off; I think I got it right.
EDIT: line 87, the ');' error, is this line: select(SEXTANT_DAEMON_LOG);
syntax error at -edited- line 87, near ");"
syntax error at -edited- line 92, near "if"
syntax error at -edited- line 99, near "if"
Unmatched right curly bracket at -edited- line 102, at end of line
syntax error at -edited- line 102, near "}"
syntax error at -edited- line 109, near "}"
syntax error at -edited- line 120, near ");"
BEGIN not safe after errors--compilation aborted at -edited- line 122.
This is the code near the error (full code here):
$MAIN_DBH = getConnection('Main');
$fs_logfile = getCSConfigValue($MAIN_DBH, 'Log', 'Sextant Update Daemon') or die "pid$[" . localtime(time()) . "] Main dbh error: " . DBI::errstr;
open(SEXTANT_DAEMON_LOG, '>>', $fs_logfile) or die "pid$[" . localtime(time()) . "] unable to open log file '$fs_logfile'\n";
$tmp = select(SEXTANT_DAEMON_LOG);
$| = 1;
select(SEXTANT_DAEMON_LOG);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Perl 没有给出很好的错误消息,但它实际上抱怨的是
"pid$$["
看起来像是访问数组@$
的无效尝试。尝试将其替换为“pid$$\[”
。我发现的方法是在附近插入
__END__
报告的第一个错误的位置。我上下移动它,直到找到导致错误的第一行,然后我尝试添加反斜杠,它修复了错误。
注意:
perl -c
非常有用在这种情况下很有用。Perl isn't giving a very good error message, but what it's actually complaining about is that
"pid$$["
looks like an invalid attempt to access the array@$
. Try replacing it with"pid$$\["
.The way I found that was by inserting
__END__
near the reported location of the first error. I moved it up and down until I found the first line that caused an error, which wasThen I tried adding the backslash, and it fixed the error.
Note:
perl -c
is very useful in situations like this.