But the document needs to be dynamic, so I tried foreach loops like this:use strict; use XML::Generator; open (RPT, ">menu.xml"); my $gen = XML::Generator->new( 'escape' => 'always', 'pretty' => 2); my $xml = $gen->Menu( $gen->Course("Appetizers"), $gen->Items( $gen->Name("Soup"), $gen->Name("Salad") ), $gen->Course("Entres"), $gen->Items( $gen->Name("Oysters"), $gen->Name("Pizza") ) ); print RPT "$xml";
But this fails at the 1st foreach. I've searhed several places, but have not yet found a solution. Is a loop like this possible? Am I taking the wrong approach? Thank you, Martinuse strict; use XML::Generator; open (NEWRPT, ">newmenu.xml"); my %myhash = ( "Appetizers" => ["Soup", "Salad"], "Entres" => ["Oysters", "Pizza"] ); my $newgen = XML::Generator->new( 'escape' => 'always', 'pretty' => 2); my $newxml = $newgen->Menu( foreach my $course (keys %myhash) { $newgen->Course("$course"), $newgen->Items( my @items = @{$myhash{$course}}; foreach my $item (@items) { $newgen->Name("$item") }) }); print NEWRPT "$newxml";
In reply to XML::Generator loop by MartinSchneider
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |