用《Learning Perl》上的一段代码来说明实现:
- #!/usr/bin/perl -w
- use strict;
- foreach(1 .. 10){
- print "Iteratin number $_.\n\n";
- print "Please input the choice: last, redo, next, or none of the above?";
- chomp(my $choice=<STDIN>);
- print "\n";
- last if $choice=~ /last/i;
- next if $choice=~ /next/i;
- redo if $choice=~ /redo/i;
- print "That wasn't any of the choices.. onward!\n\n";
- }
- print "That's all, folks!\n";
我们可以替换last,next,redo为实际需要执行的函数,修改print语句来让这个菜单更漂亮。
本文转自xiaoyuwang 51CTO博客,原文链接:http://blog.51cto.com/wangxiaoyu/494656,如需转载请自行联系原作者