in reply to Editing the contents of a variable

Thank you all for your feedback.

In context: I'm trying to write a script that I can use to selectively remove data sources from XML dumps from an RRD file.
I.e. When a datasource is obsolete and needs removed to avoid polluting the graph.

This first section of the script is to get the names of the datasources. I'll now start the next part of my script, to push them to an array.

Each of your answers is useful to help develop my own perl knowledge (and hopefully anyone else finding this thread.).
Thanks again for your help.

Regards -

Replies are listed 'Best First'.
Re^2: Editing the contents of a variable
by GrandFather (Saint) on Aug 22, 2012 at 03:52 UTC

    As ww hinted, using a parser to do the heavy lifting is better than hand rolling code to parse XML. The down side for someone starting out is typical modules (in this case XML::Twig is recommended) are pretty daunting. They look like they will take much longer to learn to use than hand rolling just the little bit of code that it seems you will need. In fact that is generally wrong. Especially for XML and HTML, unless you are generating the source files yourself, there are many subtleties and edge cases that will bite you.

    If you are writing this code to learn Perl then rolling your own parser will be very educational, but don't expect to get a reliable script written any time soon. If you are writing this to get a job done and learn some Perl along the way it is well worth spending the time to figure out how to use CPAN and (in this case) XML::Twig. Learning to use modules from CPAN is an important part of learning to use Perl effectively.

    True laziness is hard work