📄 switch
字号:
Check the lexical scoping of the switch keywords.(The actual behaviour is tested in t/op/switch.t)__END__# No switch; given should be a bareword.use warnings;print STDOUT given;EXPECTUnquoted string "given" may clash with future reserved word at - line 3.given######### No switch; when should be a bareword.use warnings;print STDOUT when;EXPECTUnquoted string "when" may clash with future reserved word at - line 3.when######### No switch; default should be a bareword.use warnings;print STDOUT default;EXPECTUnquoted string "default" may clash with future reserved word at - line 3.default######### No switch; break should be a bareword.use warnings;print STDOUT break;EXPECTUnquoted string "break" may clash with future reserved word at - line 3.break######### No switch; but continue is still a keywordprint STDOUT continue;EXPECTsyntax error at - line 2, near "STDOUT continue"Execution of - aborted due to compilation errors.######### Use switch; so given is a keyworduse feature 'switch';given("okay\n") { print }EXPECTokay######### Use switch; so when is a keyworduse feature 'switch';given(1) { when(1) { print "okay" } }EXPECTokay######### Use switch; so default is a keyworduse feature 'switch';given(1) { default { print "okay" } }EXPECTokay######### Use switch; so break is a keyworduse feature 'switch';break;EXPECTCan't "break" outside a given block at - line 3.######### Use switch; so continue is a keyworduse feature 'switch';continue;EXPECTCan't "continue" outside a when block at - line 3.######### switch out of scope; given should be a bareword.use warnings;{ use feature 'switch'; given (1) {print "Okay here\n";}}print STDOUT given;EXPECTUnquoted string "given" may clash with future reserved word at - line 6.Okay heregiven######### switch out of scope; when should be a bareword.use warnings;{ use feature 'switch'; given (1) { when(1) {print "Okay here\n";} }}print STDOUT when;EXPECTUnquoted string "when" may clash with future reserved word at - line 6.Okay herewhen######### switch out of scope; default should be a bareword.use warnings;{ use feature 'switch'; given (1) { default {print "Okay here\n";} }}print STDOUT default;EXPECTUnquoted string "default" may clash with future reserved word at - line 6.Okay heredefault######### switch out of scope; break should be a bareword.use warnings;{ use feature 'switch'; given (1) { break } }print STDOUT break;EXPECTUnquoted string "break" may clash with future reserved word at - line 6.break######### switch out of scope; continue should not work{ use feature 'switch'; given (1) { default {continue} } }print STDOUT continue;EXPECTsyntax error at - line 5, near "STDOUT continue"Execution of - aborted due to compilation errors.######### C<no feature 'switch'> should workuse warnings;use feature 'switch';given (1) { when(1) {print "Okay here\n";} }no feature 'switch';print STDOUT when;EXPECTUnquoted string "when" may clash with future reserved word at - line 6.Okay herewhen######### C<no feature> should work toouse warnings;use feature 'switch';given (1) { when(1) {print "Okay here\n";} }no feature;print STDOUT when;EXPECTUnquoted string "when" may clash with future reserved word at - line 6.Okay herewhen######### Without the feature, no 'Unambiguous use of' warning:use warnings;@break = ($break = "break");print ${break}, ${break[0]};EXPECTbreakbreak######### With the feature, we get an 'Unambiguous use of' warning:use warnings;use feature 'switch';@break = ($break = "break");print ${break}, ${break[0]};EXPECTAmbiguous use of ${break} resolved to $break at - line 5.Ambiguous use of ${break[...]} resolved to $break[...] at - line 5.breakbreak
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -