Re: Parsing outputby 1nickt (Abbot)
|on Aug 02, 2019 at 21:47 UTC||Need Help??|
Hi there again,
For the type of query that you want, being able to say select * from sub where subname = 'foo' order by date_modified desc limit 1 or similar simple SQL, is about 95% easier than trying to morph nested Perl data structures from one format into another.
I understand that you are working with a Mongo DB project, but I am not familiar with Mongo and it looks like you are storing nested structures and yet are not able to query them? If that's so, and you don't just need to read some more Mongo doc, set up an SQLite DB to crunch your data.
You can even set it up in memory in your process, populate it as you read in data, query it to analyze the data and make reports, and throw it away when the process is finished. I use exactly this technique to build nightly reports from a commercial website, reading in raw data from two or three places, building a temporary SQLite DB, and producing the reports from there.
The time it takes to figure out how to do that will not greatly exceed the time it takes to build up a huge ugly Perl program to make the same queries. Your code will be a tenth as long and 100 times more maintainable, readable, and robust.
Hope this helps!
The way forward always starts with a minimal test.