###########################
#  diesel2.pl
#     07.08.23

use strict;
use HTML::Template;

my(%t,@fld,$n);

my $template = HTML::Template->new(filename => 'diesel0.htm');
my @loop = ();

open(IN,"diesel1.txt") or die "Can't open the file diesel1.txt";

while(<IN>){
    chomp;
    @fld = split(/==>/);
    if ( $fld[0] eq 'NO1' ) {
        push(@{ $t{NOS} },$fld[1]);
        $t{NO1} = $fld[1];
    } elsif ( $fld[0] eq 'NO2' ) {
        $t{clist}{$t{NO1}} = $fld[1];
    } elsif ( $fld[0] eq 'NO3' ) {
        $t{elist}{$t{NO1}} = $fld[1];
    }
}
close(IN);

@{ $t{NOS} } = sort { lc($a) cmp lc($b) } @{ $t{NOS} };

for $n ( 0 .. $#{ $t{NOS} } ) {
    $t{NO1} = $t{NOS}[$n];
    $t{c1} = $t{clist}{$t{NO1}};
    $t{e1} = $t{elist}{$t{NO1}};
    
    my %row = (
            N1 => $t{NO1},
            C1 => $t{c1},
            E1 => $t{e1}
    );
    push(@loop, \%row);
}

$template->param(std_loop => \@loop);
open(OUT,">diesel1.htm");
print OUT $template->output;
close(OUT);