I have little problem with printing data like this, I have written script as show below for this input data

$var1={ 'data'=>{ 'employee'=>[ { 'name'=>'suraj', 'number'=>'f11a0478', 'adress'=>' badvel,kadapa,a.p,india', }, { 'name'=>'misra', 'number'=>'047902', 'adress'=>' raipur,ananthapur,a.p,india', }........... ........... ], 'company'=>{ 'name'=>'bosch', 'location'=>'banglore', 'domain'=>{ 'java'=>{ 'employee'=>[ { 'name'=>'suraj', 'number'=>'f11a0478', 'experience'=>{ 'years'=>'3', 'projects'=>'4', } }, { 'name'=>'misra', 'number'=>'047902', 'experience'=>[ { 'years'=>'1', 'projects'=>'1', }, { 'years'=>'1', 'projects'=>'1', } ] }, ] } }................ ................. };
script for above code
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; use XML::Simple; use Template; my $xml = new XML::Simple; my $data = $xml->XMLin("data.xml", ForceArray=>['dat','employee','expe +rience']); #print Dumper($data); my $template = Template->new(); my $filename = 'output1.tex'; $template->process(\*DATA, $data, $filename) || die "Template process failed: ", $template->error(), "\n"; system( "pdflatex $filename" ); __DATA__ \documentclass[a4paper,leqno,twoside]{article} \usepackage[latin1]{inputenc} \usepackage[english]{babel} \begin{document} [% FOREACH comp IN company %] [% comp.name %] [% comp.location%] employeedata: [% FOREACH employee IN comp.domain.java.employee %] [% employee.name %][% employee.number %] [% FOREACH obj IN data%] [% FOREACH beha IN obj.employee %] [% IF beha.number == employee.number && beha.name == employee.name + %] [% beha.address %], [% LAST %] [% END %] [% END %] [% END %] [% END %] [% END %] [% END %] \end{document}

from above script comparing "name and number" value in two keys in a hash and if both are same print the employee address. Its working and it printing like this as show below.

if there is three persons under employee it printing like this. person address1, person2 address, person3 address, if two employee names is there it printing like this. person address1, person2 address,, but I need to print like this if three employee names is there person address1, person2 address or person3 address. if two employee names is there like this person address1, person2 address. if only one employee name is there like this person address1.

I have maximum number of employee names is three only. I need to print like this help me how to print like this. if any mistakes is there excuse me please.

I tried like this also but problem is

[% FOREACH comp IN company %] [% comp.name %] [% comp.location%] employeedata: [% FOREACH employee IN comp.domain.java.employee %] [% employee.name %][% employee.number %] [% FOREACH obj IN data%] [% FOREACH beha IN obj.employee %] [% IF beha.number == employee.number && beha.name == employee.name + %] [% comp.domain.java.employee.size %] [% IF comp.domain.java.employee.size==1 %] [% beha.address %]. [% ELSIF comp.domain.java.employee.size==2 %] [% beha.address %],[% beha.address %]. [% ELSIF comp.domain.java.employee.size==3 %] [% beha.address %],[% beha.address %]or[% beha.address % +]. [% LAST %] [% END %] [% END %] [% END %] [% END %] [% END %] [% END %]
it is printing like this
if one employee name under employee tag is there like this person address1. if two employee names is there like this person address1, person1 address. person address2, person2 address. if three employee names is there like this person address1, person1 address or person1 address. person address2, person2 address or person2 address. person address3, person3 address or person3 address.

i can't understand what mistake i did and also I found size=3 so i written script like this can any one help me how can i print data as want.

above hole post I written person1 address instead of his address for easy writing purpose.


In reply to help me with template module to print like this by veerubiji

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.