Chinaunix首页 | 论坛 | 博客
  • 博客访问: 226455
  • 博文数量: 50
  • 博客积分: 1415
  • 博客等级: 上尉
  • 技术积分: 541
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-03 11:48
文章分类

全部博文(50)

文章存档

2010年(38)

2009年(12)

我的朋友

分类:

2009-12-09 13:46:40

#!user/bin/perl

use strict;
#function to return the average number of the array ;

sub average {
my (@num) = @_;
my $num = scalar @num;
my $total;
foreach (0..$#num) {

$total += $num[$_];
}
return ($total/$num);
}
#function to search the number of the array;

sub above_average {
my (@arry) = @_;
my $average = average(@arry);
my @num;
foreach (0..$#arry){

    push(@num,$arry[$_]) if ($arry[$_] >= $average);
}
return @num;
}

#test the sub

my @fred = above_average(1..10);
print "\@fred is @fred \n";
#test two

my @barney = above_average(100,1..10);
print "\@barney is \n".join "\t",@barney,"\n";
<STDIN>;


阅读(6502) | 评论(0) | 转发(0) |
0

上一篇:perl基础练习

下一篇:PERL 二维数组排序

给主人留下些什么吧!~~