http://qs321.pair.com?node_id=1227939


in reply to Contextual find and replace large config file

"Does anyone know of a better or more generic way to do these kind of things?"

There's lots of choices for config files. JSON and YAML are popular. Your second example is pretty close to JSON already. It would look like this as JSON:

{ "ObjectType1": { "Param1": 8, "Param2": "SomeText", "NestedObject": { "Param1": 3, "Param2": "SomeText" } }, "ObjectType2": { "Param1": 10 } }

There are perl modules to parse JSON, some streaming, if you really can't load it all into memory. There's also a really nice command line utility called "jq", see some examples here.

Note that JSON doesn't support comments, which is probably the biggest complaint about it as a configuration file format.