Think about Loose Coupling | |
PerlMonks |
Re^2: Move data into AoHby vitoco (Hermit) |
on Sep 26, 2013 at 13:39 UTC ( [id://1055832]=note: print w/replies, xml ) | Need Help?? |
Given the following table from a database:
In a JSON structure, this would be something like the following (without newlines to show the records):
My intention was to read this "special" file and translate it into a tab delimited CSV-like file, filling missing fields with default values. The problem parsing this very long line is that it's not possible to split by comma without looking at the context, because it appears in data, just like colons, quotes (escaped with a backslash), and structure indicators ([ ] and { }, not the regex special chars, BTW). JSON module can parse that file without problems, returning the AoH structure just like it was intended:
Of course, if I had to manage this structure in memory, I'd use HoH (with id as the main key) or HoA (to save space if all other fields are present in every record) instead of AoH... Or maybe a single hash (as you proposed first) with a key composed of the id value of a record and the field name for every other values... But this should be another discussion. Was I clear this time? I'm sorry, I'm translating from Spanish on the fly... ;-)
In Section
Seekers of Perl Wisdom
|
|