Great to see you using strictures. 'use warnings' is getting you the "Odd number of elements in hash assignment" message and that is telling you important stuff, even though it doesn't mean much to you yet. But before we get to that:

Remove the ; from the #! line. I suspect on a *nix box that will cause you grief, although the whole line is mostly ignored by Windows.

Use three parameter open and a lexical file handle:

open my $fIn, '<', $ARGV[0] or ...

You only make one assignment to $info using <FH> so you only ever read the first line from the file. Maybe there should be a while loop somewhere around there?

The my $fIn helps strict help you. The '<' makes it clear that you want an input file handle and avoids some potential traps with the two argument version of open.

Your while loop doesn't buy you much, especially as you create a new variable inside the loop which gets the value undef. It's fortunate (in a way) that the match controlling the loop fails for your data because otherwise you'd get a stream of using uninitialised variable warnings until you stopped the script running. What is the intent of that loop?

I wouldn't call an array that gets a word and a number 'nums' - that just seems plain wrong. 'values' would be a better name. An even better technique is:

my ($colour, $value) = split /:/, $info;

The my () makes a list so you can assign the list generated by split to the list of variables created by my.

Finally, the warning is because $word = $sum is an assignment so ($word = $sum) is a list containing the value of $sum which is probably not what you intended. However, you need to rethink the entire structure of your program. You need to loop over all the lines of the file and update colour counters as you go. A hash is the right structure for the update process so you need to keep thinking that way. Think about how you would do this if you had pieces of paper (the values) in pigeon holes (the hash) and were getting the data a line at a time over the phone.

Have another crack at this and post the result for further comment.

Perl is the programming world's equivalent of English

In reply to Re: A Beginner Needs Homework help by GrandFather
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.