![]() |
|
Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Homework helpby ikegami (Patriarch) |
on Oct 29, 2004 at 19:23 UTC ( #403881=note: print w/replies, xml ) | Need Help?? |
I found two problems: You're printing $_, but $r contains what you want to print. You should uppercase the input (using uc()). Hash lookups are case-sensitive. I also have two recommendations: It would make more sense if if ($word eq 'q'){ appeared before the split. Something's really odd with your foreach+grep. In fact, there's no need for a foreach at all. Get rid of the foreach loops and use just @result = grep {defined $_} @pay{@word}; (which simplifies to @result = grep defined, @pay{@word};). You'd be smart if you went and reread some examples using grep, and make sure you know what @hash{list} returns. Now you just have to sum up the elements of @result with something like my $sum = 0; $sum += $_ foreach @result;. You could even remove the grep, replace it with a for/foreach loop that does both the validation and the summing. In fact, that's probably a good idea. Here's how I'd do it:
In Section
Seekers of Perl Wisdom
|
|