乱世@小熊 2012-07-27 20:19 采纳率: 25%
浏览 102
已采纳

为什么这个程序有效? 我试图创建一个语法错误

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?

转载于:https://stackoverflow.com/questions/11695110/why-is-this-program-valid-i-was-trying-to-create-a-syntax-error

  • 写回答

5条回答 默认 最新

  • 程序go 2012-07-27 20:36
    关注

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

    Foo->new($bar)
    

    to be written as

    new Foo $bar
    

    So that means

    Syntax error ! exit 0;
    

    is the same as

    error->Syntax(! exit 0);
    

    or

    error->Syntax(!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).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制