No offense, but whenever I see someone say "I don't want to use a module for this", it suggests to me that they know a module is available but they just don't want to bother to learn it. I could go on about the issues with that, but most of us have heard them sooooo many times. Either you're willing to do things well or you want to scrape by. I don't mind someone "scraping by" (so long as they're not a co-worker), but to come out and tell someone that you are not willing to consider valid responses which are typically more likely to be correct...
Virtually any trivial regex solution that you will be is going to choke on embedded newlines (if any) or if the "desc" (doubtless human entered) ever contains angle brackets:
<desc>Use only with "<code>" tags</desc>
Further, a good XML module based solution will more likely handle changes to the XML in the future. In other words, if someone reorders those tags or adds more tags in the future, a regex solution will break (regexes match text) and an XML solution will be more likely to work (because it will parse the text).
This may be a rare case, admittedly, but if you learn how to do it correctly now, that's another tool under your belt (and another potential line on your resume).
By spending an extra five minutes now, you know your code is more likely to work in the future and you're lazy enough that you don't want to go back and fix it. Remember, laziness is a Perl virtue.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|