Why do Perl control statements require braces?

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

    One reason could be that some constructs would be ambiguous without braces :

    foreach (@l) do_something unless $condition;
    

    Does unless $condition apply to the whole thing or just the do_something statement?

    Of course this could have been worked out with priority rules or something, but it would have been yet another way to create confusing Perl code :-)

提交回复
热议问题