anonymized user 468275 has asked for the wisdom of the Perl Monks concerning the following question:
One of the requirements is to add a row to the change history table in the document. Having found out that .docx files are a zipped set of mainly xml files, but that Archive::Zip cannot extract to Windows, I used Archive::Zip::Member to open each file as a filehandle and for the file containing the document body:- Document.xml, (the others just get written into a new directory for rearchiving later into a new docx file), I fed its contents to XML::Parser, getting an array of deeply nested arrays and hashes back. Several arrays deep in the structure comes a "w:tbl" tag followed by an array reference to where the table starts. But I need to match a string several further levels deeper to know whether I have found the table I want to update.
So I have a fledgeling docx package with a trivial new method and two recursive traversal routines that check the ref() for how to traverse each element found. I devised an addressing mechanism as : { treetop => $arrayref, immedparent => $someref, ixork => $ArrayIndexOrHashKey } and the recursive routines aim to return the addresses for any matches to a search string.
It didn't work first time (although it does compile and do some kind of traversal already) and owing to the ridiculous amount of empty air in these structures, it takes ages to step my way through with the debugger to find out why my search routines don't do anything useful.
Meanwhile, while I headbang my way through this for another day or two, I wondered if anyone has a better idea (e.g. module(s) suggestion) for how to traverse an arbitrarily deep and baggy array of arrays and hashes looking for two matches and recording a) the reference of the next array element after the first match, b) the reference of the parent of the second match and the c) index or key within parent of the second match.
Thanks in advance!
-S
One world, one people
|
|---|