Board logo

标题: [技术讨论] 【练习-039】输出设定范围内的字母 [打印本页]

作者: sxw    时间: 2011-10-9 15:47     标题: 【练习-039】输出设定范围内的字母

下面写的好像有点问题,有时候不会输出任何类容:
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. loop:
  5. {
  6. print "请输入1-26内的任意数值:";
  7. chomp(my $num=<STDIN>);
  8. redo loop if $num!~/\d+/;
  9. #在随机生成1-26的一个数但不等于$num
  10. my $another=int(rand 26)+1;
  11. redo loop if $num==$another;
  12. if ($num < $another) {
  13.    printf "%c",$_ for ($num+96..$another+96)
  14.    } else {
  15.           printf "%c",$_ for (reverse ($num+96..$another+96))
  16.   }
  17. }
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2