in reply to How to substitute a word with an other?
Here's something to get you started with reading XML files with XML::Simple.
#!/usr/bin/env perl use warnings; use strict; use XML::Simple qw/:strict XMLin/; my $xmldata = XMLin 'FILENAME.xml', ForceArray=>[], KeyAttr=>{};
... and you'll have the data from the XML file in $xmldata. To take a look at what that Perl data structure looks like, you can do this:
use Data::Dumper; print Dumper($xmldata);
Then, you would use the methods described in the sections "Access and Printing of ..." in perldsc to access the data structure in $xmldata (also read the "Common Mistakes" section, and really, the rest of the documentation too ;-)).
One thing to note about XML::Simple is that in order to be "simple" to use, it simplifies the XML's structure a bit. For simple XML files it'll work very well, but if you have a complex input file or need to preserve the structure of the input file, that module may be too simple, in which case you can look at the many other XML modules on CPAN, such as XML::LibXML or XML::Twig.
This is just an example of how to read the XML file. What you then do depends very much on what the XML file looks like, and what you want your program to do. Try it out, write some code, and if you need any help please feel free to ask, and provide sample input, your code with a description of what it's supposed to do, any error messages, and desired output (see also How do I post a question effectively?).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to substitute a word with an other?
by fx3000 (Initiate) on May 16, 2014 at 15:30 UTC | |
by Anonymous Monk on May 16, 2014 at 15:42 UTC |