May someone please help me with the following, using PERL programming?

PART 1

Consider a file that consisting of lines that contain a color and an amount separated by colons, like:

red:27 yellow:102 green:311 yellow:12 blue:45

Write a program that calculates the total amont for each color. The final pro- gram, for the above example file, should output (not necessarily in that order):

red:27 yellow:114 green:311 blue:45

Hint: use a hash data structure where the keys are the colors, and the values are the amounts. Hint: use the match operator on each line to isolate the color and the amount. You can also use the split function with : being the delimiter.

PART 2

Consider a file that consists of lines like the following:

r1y2g3g4y2r4r3y5y3g3g6g2r1

We would like to merge all amounts with the same tag together, while pre- serving the order. For instnce, the following line should become:

r 1 y 2 g 7 y 2 r 7 y 8 g 11 r 1

Write a program to do that. Hint: use split and arrays, and check for consecutive tags.

PART 3

Write your own cat command. You should be able to use it as follows (examples)

cat -h3 filename cat -t5 filename cat filename

displays the first 3 lines displays the last 5 lines displays the entire file

Hint: what you type at the command line will be in @ARGV. So try to match the first element with something that starts with dash followed by a letter, followed by a number. If so, do what you have to do. Hint: After you determine what the first element of @ARGV is, you have to remove it form @ARGV if it is not the file name, so that <> will work property.

THANK YOU, AWESOME PERSON! :D


In reply to Splits and Arrays, PLEASE HELP:D by AwesomePerson

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.