Date: Mon, 03 Sep 2001 00:18:46 GMT From: ChaoticSun Subject: Newbie Questions Message-Id: <0ni5ptsr06rrehr3b2juha9ko27poar9jb@4ax.com> I am just beginning to learn Perl and picked up the 3rd edition of the Llama book ("Learning Perl") by Schwartz and Phoenix. So far I have run into two problems. I would appreciate any advice regarding the two applications printed below: #!perl use strict my @names = qw(fred betty barney dino wilma pebbles bamm-bamm); my $result = &which_element_is ("dino", @names); print $result; sub which_element_is { my($what, @list) = @_; print "In subroutine.\n"; foreach (0..$#list) { print "Currently looking at $list[$_] which is $_.\n"; if ($what eq $list[$_]) { return $_; } } -1; } AND #!perl use strict sub total { my $sum; foreach (@_) { $sum += $_; } $sum; } my @fred = qw (1 3 5 7 9); my $fred_total = &total(@fred); print "The total of \@fred is $fred_total.\n"; print "Enter some numbers on separate lines:\n"; my $user_total = &total(); print "The total of those numbers is $user_total.\n"; Both programs work as expected if I comment out the "use strict" line. When it is left in, the first program never executes the foreach block and the second program gives me the following error message: syntax error at ex4-1.pl line 4, near "use strict sub total " Execution of ex4-1.pl aborted due to compilation errors. What am I doing wrong?!!!!!!