#!/usr/bin/perl -w

#######################################################
# class4_11_my3
#
# a subroutine to add up its arguments
# (return their sum) - NOW using lexical variable!
# and now using setting of a parameters to nice name.
# 
# modified by Sharon Tuttle from "Learning Perl",
#    by Schartz and Phoenix
#
# last modified: 4-17-03
#######################################################

sub sum_vals4
{
    # give arguments a nicer name:
    my(@list_of_nums) = @_; 

    # $sum is a local variable, not a parameter
    my($sum) =0;

    foreach $val ( @list_of_nums )
    {
        $sum += $val;
    }
    return $sum;
}

print &sum_vals4(1, 2, 3, 4, 5), "\n";

print "enter numbers to add up, each on their own line\n";
print "   (control-d to stop):\n";
chomp(@vals = <STDIN>);

print &sum_vals4(@vals), "\n"


# end of class4_11_my3

