在PHP我可以堆栈case语句,我可以用perl做等价的吗?
switch($myValue) { case "one": case "two": break; case "three": break; default: break; }
解决方法
使用给定和何时构造实现Perl中的
Switch statements = 5.10.由于传递给给定值的智能匹配,它非常灵活.
use feature qw( switch ); use strict; use warnings; given ($value) { when ( [qw/one two/] ) { # do something } when ('three') { # do some other thing } default { # default to something } }
您甚至可以在([qw / one two /])时写(/ one | two /).