Bullock Stuart wrote:
To Whom It May Concern:
I have a problem in attempting to access a matrix style array.
If anyone can help I should be very grateful. If I have posted to the
wrong email address, my apologies and please advise me of the correct
email address to TT2 problems to.
Data Structure
===========
dataFile = (
name => "Curve Matrix"
,matrix => [
[ 0 , 365 , 1095 , 1825 , 3650 , 2555 ]
,[2.3 , 0.142 , 0 , 0 , 0 , 0 ]
,[2.4 , 0 , 1.72 , 0 , 0 , 1.71 ]
,[2.5 , 0 , 0 , 1.75 , 1.90 , 0 ]
]
);
Output
======
What I should like on the output is:
0,365,1095,1825,3650,255
2.3,0.142,0,0,0,0
2.4,0,1.72,0,0,1.71
2.5,0,0,1.75,1.90,0
Naive Attempted Solution
==================
[%- USE matrix = iterator(dataFile.matrix) %]
[% FOREACH line = matrix %]
[%- FOREACH column = line %]
[%- %][% column %] [% IF NOT column.last %],[% END %]
[%- END %]
[% END %]
As stated -- any help or pointers with the syntax welcome.
Regards,
Stuart Bullock
Here's my solution, slightly simplified.
The data:
my %vars = (
name => "Curve Matrix."
,matrix => [
[ 0 , 365 , 1095 , 1825 , 3650 , 2555 ]
,[2.3 , 0.142 , 0 , 0 , 0 , 0 ]
,[2.4 , 0 , 1.72 , 0 , 0 , 1.71 ]
,[2.5 , 0 , 0 , 1.75 , 1.90 , 0 ]
]
);
The template:
[% FOREACH line = matrix -%]
[%- line.join(',') %]
[% END -%]
The output:
0,365,1095,1825,3650,2555
2.3,0.142,0,0,0,0
2.4,0,1.72,0,0,1.71
2.5,0,0,1.75,1.9,0
I suppose, if you wanted to format individual values, you could do this:
[% FOREACH line = matrix -%]
[% FOREACH item = line -%]
[%- item %][% UNLESS loop.last; ","; ELSE; "\n"; END %][% END -%]
[% END -%]
--mark