3 ms·
As a polyglot, sometimes the existence of a certain library or interface greatly influences what language I decide to write something in. Twig is indeed time-t
by 22c 2y ago
As a polyglot, sometimes the existence of a certain library or interface greatly influences what language I decide to write something in.
Twig is indeed time-tested, but I don't see a good reason to use Twig unless you are already using Perl. I was kinda hoping this would give reasons to use Twig over proven XML libraries from other languages, but I suppose it makes sense given this article was published to a Perl specific website.
Nice write-up, though!
- mirod1 2y agoThe basic reason to use XML::Twig as opposed to XSLT would be to do XML processing while still having access to all of Perl's power, DB access, file system integration etc... things that can be clunky to do in XSLT. For what it's worth I have used XSLT too, and the basic programming patterns are surprisingly similar: an XPath selector triggers some code, the code has access to the XML tree. In both cases you have to pay some attention to when that code is being triggered. I prefer the XML::Twig way, to being able to use a regular programming language in the code, partly because I am used to it, but also because the XSLT XML syntax ends up being quite verbose, and leads to delimiter collisions. XML::Twig also lets you work with "too big to fit in memory" XML, by working at sub-tree level in a nicer (IMHO) way than SAX. I am sure there are other ways these days, but the module dates back to last century, so at the time that was pretty unique. I assume that other languages also have convenient XML libraries, so if you're more familiar with them and they work for you, then you should use them!