|Perl Monk, Perl Meditation|
Contextual find and replace large config fileby Veltro (Hermit)
|on Jan 02, 2019 at 13:01 UTC||Need Help??|
Veltro has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I hope someone can help me with some ideas on this.
Quite often I end up working with big text files (~500k lines) which have configuration data that I want to change using a Perl program. The data files often don't have any official format. The structure of these kind of files are often similar and the content could look something like the following examples:
Most of the time I want to do something like changing the values of parameters for a certain object type and leave all the other lines inside the data file 'untouched'. A very simplistic approach that I used looks like the next code example (second data example). It reads the file line by line and keeps track of which 'context' it is currently reading and acts depending on that context. It works fine (as long as the format does not change too much), however the more complex things that I want to do these kind of snippets tend to become very complex and difficult to maintain.
Does anyone know of a better or more generic way to do these kind of things? I am looking for a very simple approach (search and replace, not reading the entire data file to memory) where I can flexibly define a formula that is applied to a parameter within the scope of the context it is in.
edit:/\}/ => /$\}/