My “wisdom” on this issue is that ... there ought to be a big sign pasted over the doorway that leads to “the way you’re trying to do it now.” That sign would read:
Through me you pass into the city of woe:
Through me you pass into eternal pain:
Through me among the people lost for aye.
Justice the founder of my fabric mov'd:
To rear me was the task of power divine,
Supremest wisdom, and primeval love.
Before me things create were none, save things
Eternal, and eternal I endure.
All hope abandon ye who enter here.
“The right way to do it ... the only way to do it ...” is with an XML parser (package from CPAN). If you take something like, say, XML::Simple, this will be able to parse the XML into a hashref structure. You can then manipulate that structure any way you need to. Then, write it out.
When writing processing routines like this, I always try to follow two principles:
- Always write the output to a different file than the input. This gives you two generations of the data: “before,” and “after.”
-
Sounds silly, but ... make very sure that the manipulation that you are supposed to be doing, has not already been done. Write the code to be very defensive. Make it examine the data, looking for trouble. Make it respond gracefully and robustly in all circumstances.
| [reply] |