#!/usr/bin/perl 

use strict;
use CGI ':standard';

my $htm_mnu;
my $htm_tre;
my $htm_tre2;
my @htm_page;
my $htm_lin;

$htm_mnu=param('MNU');
$htm_tre=param('TRE');
$htm_tre2=param('TR2');

#-- czytanie pliku
open (HTM1,"<$htm_mnu") || die "ERR:read $htm_mnu, Error : $!\n";
@htm_page=<HTM1>;
close(HTM1);

#-- 
print "Content-type: text/html\n\n";
my $n=1;
foreach (@htm_page) {
  $htm_lin=$_;
  if ($htm_lin=~/##TRESC##/) {
    print "$`";
    htm_tresc ($htm_tre);
    print "$'\n";
    }
  else {if ($htm_lin=~/##TRESC2##/) {
    print "$`";
    htm_tresc ($htm_tre2);
    print "$'\n";
    }
  else {
    print "$htm_lin \n";
    }}
  $n++;
  }

exit;

#-- konec


#-----
sub htm_tresc 
{
my $htm2=$_[0];
my @htm_page2;

#-- czytanie pliku
open (HTM2,"<$htm2") || die "ERR:read $htm2, Error : $!\n";
@htm_page2=<HTM2>;
close(HTM2);

#-- 
my $n=1;
foreach (@htm_page2) {
  print "$_ \n";
  $n++;
  }
}
