Why do Perl control statements require braces?

后端 未结 8 1183
挽巷
挽巷 2021-02-07 00:05

This may look like the recent question that asked why Perl doesn\'t allow one-liners to be \"unblocked,\" but I found the answers to that question unsatisfactory because they ei

8条回答
  •  再見小時候
    2021-02-07 00:31

    In Programming Perl (which Larry Wall co-authored), 3rd Edition, page 113, compound statements are defined in terms of expressions and blocks, not statements, and blocks have braces.

    Note that unlike in C and Java, [compound statements] are defined in terms of BLOCKS, not statements. This means that the braces are requried--no dangling statements allowed.

    I don't know if that answers your question but it seems like in this case he chose to favor a simple language structure instead of making exceptions.

提交回复
热议问题