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

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

问题描述

我正在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天全站免登陆