|Just another Perl shrine|
Re: A complicated file parsing and 2D array/matrix problem.by roboticus (Chancellor)
|on Aug 25, 2012 at 13:05 UTC||Need Help??|
You oversold your problem. It's a very basic question, not a complicated one. So beginners may skip over your question, thinking that it'll need complex methods and/or algorithms, so you'll lose some possible responses. When others see the question, they'll see that it's quite simple and not interesting enough to solve, so you'll lose a lot of other possible responses.
I could just drop some code on you, but that wouldn't be very educational. What have you tried? What algorithm(s) have you considered? For simple problems, many monks want to see you put some effort into it: i.e. an attempt to solve the problem. I don't really see any effort expended, and we're not a code-writing service. If you had a problem with some code, I'd've offered some specific suggestions. If it were truly a complicated problem, and interesting enough, I might've spent some time playing with it.
Having said all that, here are a couple of hints for you:
First, if it's going to be a sparse matrix, you might consider a hash instead of an array.
You can build the structure as you read it, rather than building two arrays and then merging the arrays.
When your only tool is a hammer, all problems look like your thumb.