rsennat has asked for the wisdom of the Perl Monks concerning the following question:

hi all,

i have a xml file, and using it for reading input arguments to my test script.

for scalr and arrays no problem in storing it in a xml file. but how do i store a hash in a xml file??

thanks
rsennat
  • Comment on take input data as hash from a xml file

Replies are listed 'Best First'.
Re: storing hash in a xml file
by GrandFather (Saint) on Dec 07, 2005 at 06:06 UTC

    Use XML::Simple. From the docs:

    use XML::Simple; my $ref = XMLin([<xml file or string>] [, <options>]); my $xml = XMLout($hashref [, <options>]);

    so to create the xml from a hash:

    my %hash; ... # fill the hash my $xml = XMLout (\%hash);

    DWIM is Perl's answer to Gödel
Re: storing hash in a xml file
by rsennat (Beadle) on Dec 07, 2005 at 06:21 UTC
    I will put the question in other way,
    How to get the input arguments as hash from the xml file for the test scripts. for eg. the test script can read scalar within a tag in the xml file, but how to input and read a hash from the xml file.

    thanks
    rsennat

      Try reading the docs for the module that was suggested: XML::Simple. That should provide a more thorough answer to your question than any response here. But if you're still unclear after completing the ten minute homework assignment we've given you, don't just rephrase the question. Instead, try focusing on the one aspect of the question that continues to elude you. Again, the documentation and a few good examples can be found here.


      Dave

      Thanks. I could get that using XMLin() and XMLout() of XML::Simple module

      rsennat