good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: Parsing bracket formatted fileby Anonymous Monk |
on Sep 25, 2022 at 07:05 UTC ( [id://11147118]=note: print w/replies, xml ) | Need Help?? |
Your example shows that "sub-records" can have odd number of elements and therefore can't be "composed of KEY, VALUE pairs". Obviously, some sub-records are arrays, not hashes. With such loose brief, there's room for interpretation whether to parse sub-record into array or hash. My attempt below assumes "keep arrays for odd number of elements or if unapproved keys were encountered". (E.g. for "us-east-1 us-west-1" sub-record, are they key-value pair or 2-element list?) Obviously, these rules can be adjusted, but idea was to let Perl parse input as Perl source, with only minimal text pre-processing, and always assume arrays. Afterwards, promote some arrays to hashes if they pass rules mentioned above.
Output:
In Section
Seekers of Perl Wisdom
|
|