Obtain a switch/case behaviour in Perl 5

前端 未结 5 1047
清酒与你
清酒与你 2020-12-13 14:25

Is there a neat way of making a case or switch statement in Perl 5?. It seems to me they should include a switch on version 6..

I need this control structure in a sc

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-13 15:15

    The suggestion in Programming Perl is:

    
    for ($string) {
        /abc/ and do {$abc    = 1; last;};
        /def/ and do {$def    = 1; last;};
        /xyz/ and do {$xyz    = 1; last;};
        $nothing = 1;
    }
    

提交回复
热议问题