Perl之List::Util

#!/usr/bin/perl

use List::Util qw/max min sum maxstr minstr shuffle/;

利用 List::Util::shuffle创建一个随机排序的数组。

sub create_rand_array {

        my ($min, $max)= @_;

my @a = ($min..$max);

@a = List::Util::shuffle @a;

}

其他用法:

print max(1..10);      #10 ,最大值

print min(1..10);      #1 ,最小值

print sum(1..10);      #55 ,求和

@a = ('hello', 'ok', 'china', 'unix');

print maxstr(@a);      #unix ,字符串比较最大值

print minstr(@a);      #china ,字符串比较最小值

猜你喜欢

转载自lzqustc.iteye.com/blog/2321451
今日推荐