Why is this program valid? I was trying to create a syntax error

后端 未结 6 1288
不思量自难忘°
不思量自难忘° 2020-11-28 17:04

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.

6条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 17:39

    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).

提交回复
热议问题