It's been a while. Both since I've used Perl and come here seeking knowledge and your kind help.
Since it's been a while, I decided I would "ride the Llama" once more. So far, I've just been cracking along and enjoying a nice refresher.
But unfortunately, I seem to have hit a snag in the first exercise on chapter 4. I've stared and stared at my code...and stared some more. When I was done staring, I stared one more time.
Now. I've decided to cave and ask for help. I just don't know why my 'total' function is behaving so oddly. Here's the proglet:
----------------------------------------------------------
------------------------------------------------------#!/usr/bin/perl use strict; sub total { my $number; foreach (@_) { $number += @_[$_]; } return $number; } 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(<STDIN>); print "The total of those numbers is $user_total.\n\n";
Danke!
2006-10-01 Retitled by g0n, as per Monastery guidelines
Original title: '0dd llama'
In reply to Having problems with addition in sub by bluethundr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |