为什么这个程序有效?我试图创建一个语法错误 [英] Why is this program valid? I was trying to create a syntax error

查看:27
本文介绍了为什么这个程序有效?我试图创建一个语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 7 上运行 ActiveState 的 32 位 ActivePerl 5.14.2.我想搞砸使用 Git 预提交钩子来检测被签入的有语法错误的程序.(不知何故,我只是设法做了一个如此糟糕的提交.)所以作为一个测试程序,我随机记下了这个:

I'm running ActiveState's 32 bit ActivePerl 5.14.2 on Windows 7. I wanted to mess around with a Git pre-commit hook to detect programs being checked in with syntax errors. (Somehow I just managed to do such a bad commit.) So as a test program I randomly jotted this:

use strict;
use warnings;

Syntax error!

exit 0;

然而,它编译和执行时没有警告,退出时错误级别为零.这种有效的语法如何?

However, it compiles and executes with no warnings, and errorlevel is zero on exit. How is this valid syntax?

推荐答案

Perl 有一种称为间接方法表示法"的语法.它允许

Perl has a syntax called "indirect method notation". It allows

Foo->new($bar)

写成

new Foo $bar

就是这个意思

Syntax error ! exit 0;

error->Syntax(! exit 0);

error->Syntax(!exit(0));

它不仅是有效的语法,而且不会导致运行时错误,因为执行的第一件事是 exit(0).

Not only is it valid syntax, it doesn't result in a run-time error because the first thing executed is exit(0).

这篇关于为什么这个程序有效?我试图创建一个语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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