Perl script to create latex template.

Hi,
I have XML file and I extracted some tags and stored in hash, my data as look like this

$var1={
        'stud.xml'={ 
                   '24'=>'<address>
                           <streetname="xxxx"/>
                            <housenum="138"/">
                           </address>'
                     '20'=>'<address>
                           <streetname="xxxx"/>
                            <housenum="110"/">
                           </address>'
                         }
         'pav.xml'={ 
                   '26'=>'<address>
                           <streetname="xxxx"/>
                            <housenum="138"/">
                           </address>'
                     '27'=>'<address>
                           <streetname="xxxx"/>
                            <housenum="110"/">
                           </address>'
                         }
                         .
                         .
                         .
                 }

now I need to create latex template to the above data using perl. then I have latex compiler I will convert into PDF. help me with script.

Here are the links to help you.

What is the best Perl module to use for creating a .pdf from scratch? - Stack Overflow

http://theoval.cmp.uea.ac.uk/~nlct/latex/apps/ltxtemplate/ltxtemplate-man.pdf

tyler_durden

Hi, I tried to run this sript but it gives error like pdflatex is not recognized by an internal or external command. operable program or batch file. I installed MikTex but I dnt know how to overcome this error .

#!/usr/bin/env perl

use strict;
use warnings;

use XML::Fast;
use Template;

my $xml = <<'XML';
 <student>
      <number>24</number>
      <education>bachelors</education>
      <specialization>computers </specialization>
     -<address>
         <house_number="128"/>
         <street name="xxxx"/>
           <proddutoor/>
      <address/>
     -<details>
          <name="clar"/>
          <age="20"/>
         <sex="m"/>
       </details>
</student>
 <student>
      <number>23</number>
      <education>ph.d.</education>
      <specialization>physics </specialization>
     -<address>
         <house_number="128"/>
         <street name="xxxx"/>
           <proddutoor/>
      <address/>
     -<details>
          <name="joel"/>
          <age="20"/>
         <sex="m"/>
       </details>
</student>
XML
my $xml_hash = xml2hash $xml;

my $template = Template->new();

my $filename = 'output.tex';

#I think the following is a holdover from a previous version
#as I cannot check right now, I will leave as a comment:
#open my $fh, '>', $filename;

$template->process(\*DATA, $xml_hash, $filename)
    || die "Template process failed: ", $template->error(), "\n";

system( "pdflatex $filename" );

__DATA__
\documentclass{article}

\title{Roster}
\author{pavani}

\begin{document}
\maketitle

[% FOREACH st IN student %]
Student [% st.number %] is a [% st.specialization %] [% st.degree %] student.

[% END %]

\end{document}

That's because Windows does not recognize the pdflatex program.

Hi, I generated latex template using perl,and complied with MikTeX, its genarating pdf. I written script like this

#!/usr/bin/env perl

use strict;
use warnings;

use XML::Fast;
use Template;

my $xml = <<'XML';
 <student>
      <number>24</number>
      <education>bachelors</education>
      <specialization>computers </specialization>
     <address>
         <house_number="128"/>
         <street name="xxxx"/>
           <proddutoor/>
      </address>   
</student>
<student>
      <number>23</number>
      <education>ph.d.</education>
      <specialization>physics </specialization>
     <address>
         <house_number="12"/>
         <street name="xxxx"/>
           <kadapa/>
      </address>
</student>
XML
my $xml_hash = xml2hash $xml;

my $template = Template->new();

my $filename = 'output.tex';


$template->process(\*DATA, $xml_hash, $filename)
    || die "Template process failed: ", $template->error(), "\n";

system( "pdflatex $filename" );

__DATA__
\documentclass{article}

\title{Roster}
\author{pavani}

\begin{document}
\maketitle

[% FOREACH st IN student %]
Student [% st.number %] is a [% st.specialization %] [% st.degree %] student and his address is[%address%][%house_number%][%street name%].
[% END %]

\end{document}

when I run it its generating pdf with like this

student 24 is a computers student and his address is HASH(0x274b27c)
student 23 is a computers student and his address is HASH(0x274b27c)

but I need to print address also but it printing hash not address how to get the address element content also like this

student 24 is a computers student and his address is 
 house_number="128";
 street name="xxxx";
 proddutoor.
student 23 is a computers student and his address is 
 house_number="12";
 street name="xxxx";
 kadapa.

what should I need to change to print like this in pdf.

2) I have one more question if I am giving input like this XML data its excuting what can I do if I have one file with data same as like this,for example more number of students data in my file.

The gibberish is not the hash; you haven't deferenced the reference.
Not sure what your 2nd question is.

tyler_durden

my second question is in my code i assigned only two students information to the variable $xml. But i have 150 students information in one file how can i print all students information in pdf. in this code i am printing only two students information. like this same format i have more number of stdents information in one file, I opened that file and assigned like this

my $file;
open($file, 'formal.xml');
my $xml=$file;
my $xml_hash = xml2hash $xml;

but its not working when i given a file as input.

"its not working" is a vague statement.
In what way is it not working?

tyler_durden

like I tried in above way, open file and assign to variable and using xml2hash converting, you know after that creating latex template and print in pdf file.Extract and print the information into pdf.

Sorry, it's still unclear.