Perl语言入门(第五版) 读书笔记(九)---智能匹配与given-when结
第十五章 智能匹配与given-when结构 (use 5.010;新特性) ?say "I found Fred in the name!n" if $name ~~ /Fred/; 3. given-when结构 ?类似于C语音的switch-case,但是功能比其强。 ?use 5.010; ?given( $ARGV[0] ) {? #given语句包含在foreach中时,可以省略 ??when( $_ ~~ /fred/i ) { say 'Name has fred in it'; } #可以没有continue或break ??say "Processing";? #还可以使用when以外的语句 ??when( $_ ~~ /^Fred/ ) { say 'Name starts with Fred'; continue } #continue 结束当前when,进行下一个when ??when( $_ ~~ 'Fred' ) { say 'Name is Fred'; break } # break 跳出given-when结构 ??default { say "I don't see a Fred" } ?} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |