读 《C程序员精通Perl》http://book.douban.com/subject/1232075/ 3.1节 笔记
#!/usr/bin/perl
use strict;
use warnings;
my @array = (10, 20, 30, 3, 38, 7, 80);
my $biggest;
my $smallest;
$biggest = $array[0];
$smallest = $array[0];
print "number of array = $#array\n";
for (my $index=1; $index <= $#array; $index++) {
print "array[$index] = $array[$index]\n";
if ($array[$index] > $biggest) {
$biggest = $array[$index];
}
if ($array[$index] < $smallest) {
$smallest = $array[$index];
}
}
print "smallest = $smallest, biggest = $biggest\n";
运行结果:
[root@localhost perl_practice]# ./array.pl
number of array = 6