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

Hello
Hopefully some one could help me with this.
I got a cgi param with severall values
my @tc = param("checkbox"); #like: 001.001 002.001 003.001 004.001

And what to save it into a xml like:
<exec> <tc id="001.100"></tc> <tc id="002.100"></tc> <tc id="003.100"></tc> <tc id="004.100"></tc> </exec>

Other script will use this as a config file and add som more information to the xml file
I got it to work with a "static" hash but unable to use the @tc to add the elements.
my $xml = new XML::Simple (Outputfile => $conf, RootName=>'exec'); $exec = { 'tc' => [ { 'id' => '001.001' }, { 'id' => '002.001' }, { 'id' => '003.001' }, ] }; $data = $xml->XMLout($exec); print Dumper($data); }

Replies are listed 'Best First'.
Re: Adding CGI params to XML-file
by jettero (Monsignor) on Jul 24, 2007 at 11:24 UTC

    Probably, all you need is a nice map to get things rolling.

    $exec = { 'tc' => [ map {{ id=>$_ }} $cgi->param('checkbox') ] };

    -Paul

      Got it to work by using:
      $exec = { 'tc' => [ map {{ id=>$_ }} @tc ] };

      Have to read up on map
      Thanks a lot