It's been a long week, and I'm having some trouble wrapping my brain around this one..
I have a series of records in an array:
[tt]
C001,AAAA,ADDR
C002,AAAA,ADDR
C003,BBBB,ADDR
C004,CCCC,ADDR
C005,DDDD,ADDR
C006,DDDD,ADDR
C007,DDDD,ADDR
[/tt]
I want to put this into a hash of arrays with the first column as the key, then add an additional item to the array - it should end up structured like this:
[tt]
C001 => AAAA,ADDR,1 of 2
C002 => AAAA,ADDR,2 of 2
C003 => BBBB,ADDR,1 of 1
C004 => CCCC,ADDR,1 of 1
C005 => DDDD,ADDR,1 of 3
C006 => DDDD,ADDR,2 of 3
C007 => DDDD,ADDR,3 of 3
[/tt]
The duplicate values will always be consecutive in the original data, but I need to keep the relationship between the key/value so that C002 won't get "1 of 2" and C001 gets "2 of 2". Due to the random ordering of hashes, maybe an array of arrays would be better here? To create the 1 of n, I'm thinking a second hash would be needed to keep track of duplicates.
Any suggestions would be appreciated.. it's mainly the logic I'm having trouble with - I also don't have much experience accessing data structures like this, but I think I can figure that part out.
Thanks!
- jt
I have a series of records in an array:
[tt]
C001,AAAA,ADDR
C002,AAAA,ADDR
C003,BBBB,ADDR
C004,CCCC,ADDR
C005,DDDD,ADDR
C006,DDDD,ADDR
C007,DDDD,ADDR
[/tt]
I want to put this into a hash of arrays with the first column as the key, then add an additional item to the array - it should end up structured like this:
[tt]
C001 => AAAA,ADDR,1 of 2
C002 => AAAA,ADDR,2 of 2
C003 => BBBB,ADDR,1 of 1
C004 => CCCC,ADDR,1 of 1
C005 => DDDD,ADDR,1 of 3
C006 => DDDD,ADDR,2 of 3
C007 => DDDD,ADDR,3 of 3
[/tt]
The duplicate values will always be consecutive in the original data, but I need to keep the relationship between the key/value so that C002 won't get "1 of 2" and C001 gets "2 of 2". Due to the random ordering of hashes, maybe an array of arrays would be better here? To create the 1 of n, I'm thinking a second hash would be needed to keep track of duplicates.
Any suggestions would be appreciated.. it's mainly the logic I'm having trouble with - I also don't have much experience accessing data structures like this, but I think I can figure that part out.
Thanks!
- jt