Hi,
I'm trying to read data in from a file which has many lines, each with 5 different fields. I'm trying to group them using Field1 as a hash key. In the values, I want to put a reference to a 2D array.
For example, if my file is:
Line1: Field1:A Field2:40 Field3:45 Field4:red Field5:blue
Line2: Field1:B Field2:34 Field3:87 Field4:green Field6:black
Line3: Field1:A Field2:33 Field3:44 Field4:blue Field5:green
then I want to make a hash with keys 'A' and 'B'. The value for $hash{A} is a reference to a 2d array, which in this case is an array of 2 arrays, the first holding all the elements of Line1, the second holding all the elements of line2.
I'm dealing with hashes, references, and multidemensional data structures for the first time, and am having a bit of difficulty with this problem. Can anyone help? I'm trying basically to read the data in from a file format similar to above, and then access the elements in the 2d array - I think I would be able to do this if each step was separate, but putting it all together is proving quite difficult.
Thanks for any help...
I'm trying to read data in from a file which has many lines, each with 5 different fields. I'm trying to group them using Field1 as a hash key. In the values, I want to put a reference to a 2D array.
For example, if my file is:
Line1: Field1:A Field2:40 Field3:45 Field4:red Field5:blue
Line2: Field1:B Field2:34 Field3:87 Field4:green Field6:black
Line3: Field1:A Field2:33 Field3:44 Field4:blue Field5:green
then I want to make a hash with keys 'A' and 'B'. The value for $hash{A} is a reference to a 2d array, which in this case is an array of 2 arrays, the first holding all the elements of Line1, the second holding all the elements of line2.
I'm dealing with hashes, references, and multidemensional data structures for the first time, and am having a bit of difficulty with this problem. Can anyone help? I'm trying basically to read the data in from a file format similar to above, and then access the elements in the 2d array - I think I would be able to do this if each step was separate, but putting it all together is proving quite difficult.
Thanks for any help...