python小菜 2012-07-27 20:19 采纳率: 0%
浏览 228
已采纳

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

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条回答 默认 最新

  • 撒拉嘿哟木头 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 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置