Please send questions to st10@humboldt.edu .
#!/usr/bin/perl -w

#######################################################
# lect03_args1
#
# a subroutine to add up its arguments
# (return their sum)
# 
# modified by Sharon Tuttle from "Learning Perl",
#    by Schartz and Phoenix
#
# last modified: 9-6-04
#######################################################

#------------------------------------------------
# sum and return the sum of all arguments passed
#------------------------------------------------

sub sum_vals
{
    $sum = 0;

    # remember: @_ is filled with all of the arguments 
    #    in each call

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

print "about to sum 1 through 5: ";
print &sum_vals(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 "the sum of the valures you entered was: ";
print &sum_vals(@vals), "\n";


# end of lect03_args1