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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |