in reply to A Beginner Needs Homework help

There's just too much wrong with your code to even begin trying to fix it. The secret to learning how to code is to do two things:

Here's an example that actually works as a one liner. I'm guessing it will be unacceptable to turn a one liner in as your homework answer so you'll have to figure out how it works before rewriting it.
E:>perl -ne "BEGIN{my %stuff = ()}; @items=split q|: |; $stuff{$items[0]} += $items[1]; END{for(keys %stuff){print qq|$_:$s +tuff{$_}\n|}};" fakedata.dat blue:45 red:27 green:311 yellow:114

Celebrate Intellectual Diversity

Replies are listed 'Best First'.
Re^2: A Beginner Needs Homework help
by Swizzlestix617 (Novice) on Apr 10, 2014 at 04:23 UTC

    Is it really that bad :( oddly enough most of that code was given to me by the professor of the class.

    You're right that I'm uncomfortable with the language, but I don't have a choice when it comes to doing homework because that's how I'm graded.

    The reading existing programs makes sense, and I'll try to do that more. Where can I find beginner programs to read? Is there a thread for that here at perlmonks?

    Thanks for the advice, I really appreciate it.

      Just poke around this section of the Monastery. Most of the code will be way beyond you and some of it is bad, but there will be bits that will help and most of the really bad code will have follow up comments saying why it is bad, which is really better for learning from in many ways. The goodness of good code is seldom commented on, but having a "why this is bad" and a contrasting good example can help a lot in understanding the language and the way it is used.

      Perl is the programming world's equivalent of English
Re^2: A Beginner Needs Homework help
by boftx (Deacon) on Apr 11, 2014 at 02:20 UTC

    I must strongly disagree with the advice to start with one-liners in perl! By all means, write full scripts, even if they fail. You will find they are a lot easier to debug using simple techniques like the judicious use of print statements and such than trying to figure out what went wrong with a one-liner.

    The fact that you are using strictures is a very good sign and they will point you to what might be wrong.

    It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.