Hello
 
Example_File : machines.txt
======================
name,     os,          ip,            Connect_with,   Customer
apollo,   RedHat 7.3,  10.100.5.100,   Telnet,        Frieslandbank
hera,     RedHat 7.2,  10.100.33.227,  SSH,           PON
juno,     Solaris 8,   10.100.6.41  ,  SSH ,          SNV
artemis,  RedHat 7.3,  10.100.6.42  ,  Telnet,        BLA
 
And wanted from the  "machines.txt" a .html file from it with headers in the
order that they are in the machines.txt file. 
 
Wrote the next code to do so because I could not get at the headers ( name ,
os , ip ... ) in the order they are in the machines.txt file. (
machines.keys gave nothing back , machines.0.key gives them back in random
order , yes it's a hash. ) 
 
 
Template file : machines.tt
=====================
[% USE machines = datafile('machines.txt',  delim = ',') %]
[% PERL %]
my @lables=();
my $headers;
   open ( TXT , "< machines.txt " ) or die "no such file"  ;
   @lables=split(/\s*,\s*/,readline ( TXT ));  # assume headers are on the
first line
  close TXT; 
  chomp $lables[$#lables];
  # export to the namespace of Template ?, it , seems to do so
  $stash->set( headers => [EMAIL PROTECTED] );    
[% END %]

<HTML><BODY>
<Table border=1 cellpadding=0 cellspacing=0
STYLE="font-family:Arial;font-size:9px">
<TR>
[% FOREACH lable IN headers -%]
<TH bgcolor="yellow">[% lable %]</TH>
[% END -%]
</TR>
[% FOREACH machine IN machines -%]
<TR>
[%- FOREACH lable IN headers %]
[% IF machine.$lable == "" %]
 <TD>&nbsp</TD>
[%- ELSE -%]
<TD>[% machine.$lable %]</TD>
[%- END %]
[%- END %]
 
 
Now I must run it : tpage --eval_perl machines.tt
Is there a more elegant way to get at the headers in order they are in the
machines.txt. 
 
Thanks in advance : Arno Teunisse
 

Reply via email to