in reply to To find the last occurence and replace in perl
IMHO, “an XML-parsing module” is the only way to go, and XML::LibXML is an excellent choice, since it employs a binary module that is quite likely to be the same one that was used to produce the file. A very real consideration when dealing with XML files “manually” is that, sooner or sooner, the line-by-line format of the file will vary from whatever your hand-rolled program was built to expect. (And it is most likely to do so at 4:45 PM on the evening of your child’s piano recital ... don’t miss it, Dad ...)
Therefore: use a module/library. Period. There are actually several good ones to choose from ... XML::Twig is another good war-horse aimed especially at b-i-g files. And leave us not forget XML::Simple. Treat the XML file as an abstract thing, which the module magically knows how to manipulate for you. You will be rewarded with a durable, long-lasting solution to the problem that won’t have to be revisited, no matter what the next XML file looks like.
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: To find the last occurence and replace in perl
by Laurent_R (Canon) on Dec 31, 2014 at 12:06 UTC |