Perl入门小程序

#!/usr/bin/perl -w
#output the largest number from a file
$max_number = &max(3,5,10,4,6) ;
sub max
        {
        my($max_sofar_number) = shift @_ ;
        foreach (@_)
                {
                        if($_ > $max_sofar_number)
                                {
                                        $max_sofar_number = $_ ;
                                        }
                        }
        $max_sofar_number ;
        }
print "The largest number is $max_number \n";
以上代码是计算多个数的最大数,感觉和C的写法简单了不少,真乃浓缩的是精华..
 

你可能感兴趣的:(职场,perl,休闲)