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

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

#-----------------------------------------------------
# sum the values passed as arguments and return their
#    sum --- using better style! (because using
#    a non-global lexical variable instead)
#----------------------------------------------------

sub sum_vals2
{
    my($sum);
    $sum = 0;

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

print &sum_vals2(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_vals2(@vals), "\n";


# end of lect03_my2