Well, I'm not a newbie in Perl, but sometimes I like to get things complicated ...
Context :
So I've been requested to produce configs based on a template from Excel files. Challenge accepted, I could read the template in a given Excel file, retrieve cell format , read the content and call a function which would search and replace given that
% var % would match data in a data structure received by the program. Then, write a new Excel file with the result. Everybody is happy with that.
Problem :
Now they want to send me arrays of data, to create config lines such as ip address 10.10.10.10 255.255.255.255
So I thought I could use the looping system in TT , such as
[% FOREACH item IN secondaries %]
ip address [% item.ip %] [% item.mask %] secondary
[% END %]
I got it to work, but only if the 3 lines for the loop are in the same cell. Then it gets funky, and I think the problem is with encoding or something like that, where I get totally lost. I get :
"
blank
ip address bla bla
blank
ip address bla bla
blank
"
I'm totally clueless. In fact I adjusted encoding and binmode while creating the Template->new object and calling the process sub
sub template_s_r {
my ($lineref, $dataref) = @_;
my $val;
my $tt = Template->new({
ENCODING => 'utf8'
});
$tt->process(\$lineref, $dataref, \$val, {binmode => ':utf8'}) or die
+ $$tt->error, "\n";
return $val || 0;
}
and I found out I could add the "text wrap" format to the cell. Which I did. But the result is ... crappy ?
And when I try to copy and paste the content of this cell it litterally outputs "ip address bla bla\nip address bla bla\n" (including the ")
Can someone help me on this one please ?
Cheers,
Luc