veerubiji has asked for the wisdom of the Perl Monks concerning the following question:
I have little problem with printing data like this, I have written script as show below for this input data
script for above code$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', } ] }, ] } }................ ................. };
#!/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
it is printing like this[% 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 %]
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: help me with template module to print like this
by Eliya (Vicar) on Nov 09, 2011 at 17:32 UTC | |
by veerubiji (Sexton) on Nov 09, 2011 at 21:37 UTC | |
by Eliya (Vicar) on Nov 09, 2011 at 23:01 UTC | |
by veerubiji (Sexton) on Nov 10, 2011 at 08:25 UTC | |
|
Re: help me with template module to print like this
by jethro (Monsignor) on Nov 09, 2011 at 17:47 UTC | |
|
Re: help me with template module to print like this
by Anonymous Monk on Nov 09, 2011 at 17:04 UTC | |
|
Re: help me with template module to print like this
by Anonymous Monk on Nov 10, 2011 at 08:08 UTC |