Perl计数器

jrhapt01:/home/tomcat/sbin> cat test.out 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
You have new mail in /var/spool/mail/tomcat
jrhapt01:/home/tomcat/sbin> wc -l test.out 
15 test.out

jrhapt01:/home/tomcat/sbin> cat test.pl 
 open( D, "<", "test.out" ) || die "$!
";
  while (<D>) 
              {
              $num++;
              print "$num is $num
";
}

jrhapt01:/home/tomcat/sbin> perl test.pl 
$num is 1
$num is 2
$num is 3
$num is 4
$num is 5
$num is 6
$num is 7
$num is 8
$num is 9
$num is 10
$num is 11
$num is 12
$num is 13
$num is 14
$num is 15

原文地址:https://www.cnblogs.com/hzcya1995/p/13351638.html