Why do Perl control statements require braces?

后端 未结 8 1299
挽巷
挽巷 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

    Isn't it that Perl allows you to skip the braces, but then you have to write statement before condition? i.e.

    #!/usr/bin/perl
    
    my $a = 1;
    
    if ($a == 1) {
        print "one\n";
    }
    
    # is equivalent to:
    
    print "one\n" if ($a == 1);
    

提交回复
热议问题