I am very new to Perl and XML so please forgive me if I sound like a noob.
In my .pl I am using XML::Simple, Data::Dumper, and HTML::Template to try to display info from an xml file to an html template. I have read and reread the CPAN articles for all the mods I am using, but still can't figure this out.
My XML looks like this:To get this in perl I have:<document> 'employee' =>{ 'department' => [ 'Operations Hardware', 'Corporate Marketing', 'Legal', 'Human Resources', 'Finance' ] } </document>
and in my .tmpl I have:#!/perl #use strict; use lib 'C:/xampp/perl/site/lib'; use HTML::Template; $ENV{XML_SIMPLE_PREFERRED_PARSER} = 'XML::Parser';<br< use XML::Simple; use Data::Dumper; my $template = HTML::Template->new(filename => 'file'); my $xml = XMLin('file', ForceArray => ['option']); my @deptartment = @{ $xml->{employee}->{department} }; $template->param(DEPT => @deptartment); print $template->output;
<+font size="4">Department: </+font> <+ul><+li><select name="dept"> <TMPL_LOOP DEPT> <option value="<TMPL_VAR EMP_DEPT>"><TMPL_VAR EMP_DEPT></option> + </TMPL_LOOP> </select></+li> </+ul>
I'm not getting any errors, but the drop-down list in the html that gets displayed is empty. I have a feeling that I'm either (1) not getting the data from the .xml correctly, or (2) not giving the .tmpl the data in the correct format.
Please help!| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |