Subroutine subroutine

 

#! /usr/bin/perl
use strict;
use warnings;
print "\n---------summation_STDIN_parameter----------\n";
sub total{
    my $array_len = @_;
    my $sum = 0;
    foreach(0..$array_len){
        $sum += $_[$_];
        #sum += 1;
    }
    return $sum;
}
my @comma = qw{ 3 5 1 7 9};
my $dash = &total(@comma);
print "Sum is: $dash.\n";
print "Enter some numbers on seperate lines:";
my $dollar_sign = &total(<STDIN>);
print "Sum of those numbers is: $dollar_sign.";
print "\n---------summation_STDIN_parameter----------\n";
        
print "\n---------_sum_1..1000----------\n";
#my $dot_operator;
my $dot_operator = &total(1..1000);
print "Sum of 1..1000 is: $dot_operator.";
print "\n---------_sum_1..1000----------\n";

Guess you like

Origin www.cnblogs.com/books2read/p/11004049.html