I seem to keep running into the same problem, and as of yet I have not come up with a good way to solve it. Basically here is the deal. I get an some input data. Usually something to the effect of a bunch of lines that include category A and category B and some other junk. Usually there are six or eight values for category A and six or eight for category B (sometimes there is more sometime there is less last time I had to do this there were six and eight so the numbers are fresh). so far we have data that looks like this.
CatA:CatB:something:else:andSuch
What I need to end up with is a grid with A cross referenced with B. so ideally something like this.
|______A_______________________________________
B | the value of some other field goes in here
|
Sorting the keys would be nice, but that seems like it would be the easy part. Basically the main thing I am trying to do in all of my attempt at this is to print stuff out in nice easy to read grid format.
So far I have ran into this problem three times in the last three years , once in a class and twice at work. As of yet I have not come up with a solution I like yet. They all seem cludgy and more complicated than I like them to be.
My solutions so far have been.
1. a multi dimensional array
2. the same idea but with hashes because I was using strings I wanted to look them up by name rather than an array index.
3. I built a rather shoddy object which
jeffa helped me to make much better, but the solution to the problem still sucked.(my solution not his)
The thing with all of these solutions is that they all seem to suck and use about 50 times more indirection / smoke and mirrors than need be. Anyone have any suggestions before this comes back to haunt me next year?
here is the code for the best attempt yet
Thanks
Josh