Why do Perl control statements require braces?

后端 未结 8 1179
挽巷
挽巷 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:26

    Perhaps not directly relevant to your question about (presumably) Perl 5 and earlier, but…

    In Perl 6, control structures do not require parentheses:

    if $x { say '$x is true' }
    
    for  -> $s { say "[$s]" }
    

    This would be horrendously ambiguous if the braces were also optional.

提交回复
热议问题