high water mark 算法(返回最大值)

上一篇 / 下一篇  2008-11-12 10:46:47 / 个人分类:Perl

use warnings;
sub max{
 my $num;
 foreach (@_){
  if ($num < $_){
   #print $num, "\n";
   $num = $_;
  }
 }
 $num;
}
@numbers = qw /342 6436 43 1 -13 55555 431/;
print "The max number is ", &max(@numbers), ".\n";

###################################################
Print log is as below:

C:\Perl\learn>"high-water mark.pl"
Use of uninitialized value $num in numeric lt (<) at C:\Perl\learn\high-water ma
rk.pl line 5.
The max number is 55555.


TAG: Perl high water mark 返回最大值

引用 删除 风雪夜归人   /   2010-08-03 17:28:32
5
 

评分:0

我来说两句

日历

« 2024-05-02  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 47903
  • 日志数: 80
  • 建立时间: 2008-10-27
  • 更新时间: 2009-07-17

RSS订阅

Open Toolbar