[EMAIL PROTECTED] wrote:
I am doing some homework from the book Learning Perl chapter 4
excercise 1,
Looking at the script below, I wonder why line 6 (print "Enter some
numbers on separate line: ";) is not printed immediately after the
previous print.
I don't understand what you mean. However, the code below confuses me
for another reason.
use strict;
use warnings;
my @fred = qw/1 3 5 7 9/;
my $fred_total = &total(@fred);
print "The total of [EMAIL PROTECTED] is $fred_total.\n";
print "Enter some numbers on separate line: "; ## line 6
my $user_total = &total(<STDIN>);
When I tried the program, that line didn't work for me. Shouldn't it
rather be for instance:
my $user_total = total( split ' ', <STDIN> );
so that <STDIN> gets evaluated in scalar context?
print "the total of those numbers is $user_total.\n";
sub total {
my $sum;
foreach (@_){
$sum += $_;
}
$sum;
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/