in reply to Re: Is there a module for object-oriented substring handling/substitution?
in thread Is there a module for object-oriented substring handling/substitution?
Well, there have been several times in the past I would have found a module like this useful. My current use-case, which led to me writing this thread, is updating table values in a wiki page by programmatically editing the page's source code (which is available in MediaWiki format).
More precisely, the problem at hand is like this:
Within a wiki page, there is a special section (identified by it's section header). This section in turn can have an arbitrary number of subsection (each with a unique subsection header). Each of these subsections contains, among other things, a special table.
The Perl script is supposed to update the values in a specific column in each of these tables (identified by the word in the column's header cell). Which value goes into a particular table cell in that column, depends on the corresponding value in the first column (i.e. the ID column), as well as the title of the subsection that the table belongs to.
Now, the Perl script should play nice with human editing of the same wiki page. Humans will fill in the remaining columns of the aforementioned tables, as well as the rest of the wiki page, and may freely add formatting, move things (like table rows and columns) around, etc.
The Perl script must not touch *anything* on that wiki page except for the specific values it substitutes for new values. This also means no whitespace or formatting changes, so using a generic wiki text parser and dumper is out of the question.
Last but not least, the solution should be elegant and easy to maintain and expand. For example if the wiki page is radically re-factored so that the script breaks, I want to be able to fix the script easily (even if I haven't looked at its Perl source code for months), i.e. without having to write complex five-line regexes from scratch. And in the future I might want to add support for automatically adding new table rows if expected values in the ID column were not found in one of the tables, and things like that - so the design should be flexible enough to account for that.
In the absence of a module like I described in the OP, I would be using s/.../CODE/e blocks for this, but as I hinted in the OP, this might not provide the desired maintainability and elegance.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Is there a module for object-oriented substring handling/substitution?
by roboticus (Chancellor) on Jan 26, 2013 at 17:25 UTC | |
by smls (Friar) on Jan 26, 2013 at 22:44 UTC | |
Re^3: Is there a module for object-oriented substring handling/substitution?
by LanX (Saint) on Jan 26, 2013 at 20:31 UTC | |
by smls (Friar) on Jan 26, 2013 at 21:54 UTC | |
by LanX (Saint) on Jan 26, 2013 at 22:08 UTC | |
by smls (Friar) on Jan 26, 2013 at 22:38 UTC | |
by Anonymous Monk on Jan 28, 2013 at 09:28 UTC |