perl foreach

找错:
#!/usr/bin/perl

use warnings;
use strict;

sub message{
  my $quant = $_; #这里$_是个无效值,改成$quant=shift或$_[0]
  my $mess;
  $mess = "$quant glasses of Lemonade on the wall\n";
  if ($quant eq 1){
    $mess = s/glasses/glass/;#=改成=~ 
  }
  print $mess;
}
foreach (0..20){ #改成for(my $i = 20; $i >= 0; $i--)
#因为范围操作符从左边的数字计数到右边,每次加1,以产生一连串的数字。
  &message($_); #改成&message($i);
}
预期结果:
20 glasses of Lemonade on the wall
19 glasses of Lemonade on the wall
18 glasses of Lemonade on the wall
17 glasses of Lemonade on the wall
16 glasses of Lemonade on the wall
15 glasses of Lemonade on the wall
14 glasses of Lemonade on the wall
13 glasses of Lemonade on the wall
12 glasses of Lemonade on the wall
11 glasses of Lemonade on the wall
10 glasses of Lemonade on the wall
9 glasses of Lemonade on the wall
8 glasses of Lemonade on the wall
7 glasses of Lemonade on the wall
6 glasses of Lemonade on the wall
5 glasses of Lemonade on the wall
4 glasses of Lemonade on the wall
3 glasses of Lemonade on the wall
2 glasses of Lemonade on the wall
1 glass of Lemonade on the wall
0 glasses of Lemonade on the wall

你可能感兴趣的:(职场,perl,foreach,休闲,改错)