From: Grant McLean Newsgroups: comp.lang.perl.announce,comp.lang.perl.modules Subject: ANNOUNCE: XML::Simple version 1.0 Date: 29 Nov 1999 17:01:40 GMT Organization: The Web Limited Lines: 112 Approved: merlyn@stonehenge.com (comp.lang.perl.announce) Message-ID: <81ubhk$8au$1@play.inetarena.com> NNTP-Posting-Host: halfdome.holdit.com X-Disclaimer: The "Approved" header verifies header information for article transmission and does not imply approval of content. Hi All I have just uploaded XML::Simple version 1.0 (first non-beta release) to CPAN. What is XML::Simple and why would you want to use it? SCENARIO I We've all been there - we have a script that is being used in multiple places. Each copy of the script has some global variables defined at the top which hold configuration information. We know that breaking the config data out into a separate file would have multiple benefits: * Simpler version control - all copies of the script are identical * Simpler configuration management * Non programmers can configure the script But the thing that holds us back is we don't want to have to invent another config file format and implement a parser for it. Sure there are existing modules for working with .ini style config files but you lose the flexibilty that using say a global hash gives you. XML::Simple allows you to use XML format for your config files without the burden of having to learn about XML parser API's and object models. You can 'slurp' in an XML formatted config file with the following two lines of code: use XML::Simple; my $Config = XMLin(); XML::Simple uses sensible defaults for the name and location of the config file but you can override these with arguments to XMLin() if necessary. XML gives you the power to define complex nested configuration structures. If you have a basic understanding of HTML, you can pick up XML very quickly. But for an even quicker start, you can take an existing configuration stored in a hash and create an XML file using XMLout(): my $Config = { ... your data here ... } print XMLout($Config); SCENARIO II Your boss says to you ... "I've got some data in a .xml file that I need to analyse in a report by lunch time - can you turn it into something I can work with?" Unfortunately you haven't worked with XML before and the 'man page' for XML::Parser look's fairly intimidating so you try this: use XML::Simple; use Data::Dumper; my $Data = XMLin('datafile.xml'); print Dumper $Data; Then you say "Hey it's not XML any more, it's Perl!". Then in the blink of an eye you've dumped the records out into a flat file for import into a spreadsheet, or two blinks later you've used Win32::ODBC to put it directly into Excel or three blinks later you've used DBI to put it into a database or GIF::Graph to directly dump some summary charts or ... (you get the picture). SCENARIO III You fill in the blanks: ......... XML ......... Perl ......... quick ......... GREAT, HOW DO I GET IT? The package should be winging its way to your local CPAN mirror: http://www.perl.com/CPAN/authors/id/G/GR/GRANTM/XML-Simple-1.00.tar.gz Or the latest version is available from: http://web.co.nz/~grantm/cpan/ DO I NEED ANYTHING ELSE? Yes, XML::Simple is just a layer on top of XML::Parser. If you're running ActiveState's Perl for Win32, XML::Parser comes with the distribution. If you're running on another platform and don't have XML::Parser, the following should do the trick: perl -MCPAN -e 'install XML::Parser' XML::Simple itself is 100% pure Perl so if you have trouble installing the package you can just drop Simple.pm into your Perl lib/XML directory. (Of course if there's a problem with my Makefile.PL you should probably tell me so I can fix it). Regards Grant McLean