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


In reply to Re: A Beginner Needs Homework help by InfiniteSilence
in thread A Beginner Needs Homework help by Swizzlestix617

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.