CSCI 132 Practical Unix Programming Homework 5 Due 11/1

    CSCI 132 Practical Unix Programming Homework 5 Due 11/14/08 Saad Mneimneh Computer Science Hunter College of CUNY 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 program 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: r 1 y 2 g 3 g 4 y 2 r 4 r 3 y 5 y 3 g 3 g 6 g 2 r 1 We would like to merge all amounts with the same tag together while preserving 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 displays the first 3 lines cat -t5 filename displays the last 5 lines cat filename 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.
    Attachments:

                                                                                                                                      Order Now