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

Hi monkers. I need to export a hash with the next structure to xml:
%index{$name}{"SID"} = value
      {"level"} = value
      {"service"} = value
      {array with values}
Im triying to do with xml::dumper but i feel like a nerd and i really dont know how i can do, because when i type use XML::Dumper, its takes the next line as the file (???) and told me it can't export it. This its the code that i suppuose i must use to export my hash to a xml file:
foreach $control_clase (keys (%clases)){                            
  if ($control_clase eq $index{$name}{"nivel"}) {                   
  		$index{$name}{"clase"} = $clases{$control_clase} }          

Replies are listed 'Best First'.
Re: How to export hash to xml file
by zentara (Archbishop) on Jan 14, 2009 at 11:34 UTC
      cool, but this examples shows how write a "small" and "declared" hash, i have a big one with the structure i told you with around 5000 keys with his values. So i need to way to give something like a :
      foreach $control_key (%my_huge_hash)
      and use the $control_key to walk in the hash and make the xml. In all the examples i saw, all the FAQs and tutorials told me how i can do that with a small hash (with the values declared). I have in every hash key a variable that imports from a while loop that reads a text file to this hash . Thanks!
        Maybe you can use this example as a base:
        #!/usr/bin/perl use warnings; use strict; # by jdporter of perlmonks, converts a dir tree to xml use File::Find; use XML::Simple; #my $root = shift or die "Usage: $0 rootdir\n"; my $root = shift || '.'; my %tree; find( sub { #print "$File::Find::name\n"; my @path = split m,/,, $File::Find::name; my $tree = \%tree; $tree = (($tree->{'dir'} ||= {})->{shift @path} ||= {}) while @path > ( -d _ ? 0 : 1 ); @path and # it's a file push @{ $tree->{'file'} ||= [] }, shift @path; }, $root ); print XMLout( \%tree );

        I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: How to export hash to xml file
by moritz (Cardinal) on Jan 14, 2009 at 12:10 UTC
      hi moritz, i agree but its not the same, because in my first post, this its regarding when i try to load the data from an xml file to perl, and here, its wrinting from an hashref to and xml file. But if you think this post should get linked to my other post, just tell it to me and i close this one and keep posting in the other. Thanks !
Re: How to export hash to xml file
by Anonymous Monk on Jan 14, 2009 at 11:01 UTC
Re: How to export hash to xml file
by vek (Prior) on Jan 14, 2009 at 18:43 UTC
      Thanks.....sorry im a little nerd with this i have the programming foundations not well seated in my mind. I'll try and keep you posted. Thanks anyway!