您的位置:首页 > 职场人生

Perl脚本菜单的简单实现

2011-02-15 23:01 239 查看
用《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语句来让这个菜单更漂亮。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  职场 休闲 菜单 perl STDIN