Section %N1%
Sub-section %N2%
####
Section 1
Sub-section 1
Sub-section 2
Sub-section 3
Section 2
Sub-section 1
Sub-section 2
Sub-section 3
####
#!/usr/bin/perl
my ($file,$n1,$n2,$tpl);
$file = shift;
$n1 = shift;
$n2 = shift;
open(F,'<',$file) || die;
while(){ $tpl .= $_; }
close(F);
if ($n2){
for($i1=1;$i1<=$n1;$i1++){
for($i2=1;$i2<=$n2;$i2++){
$str = $tpl;
$str =~ s/%N1%/$i1/gi;
$str =~ s/%N2%/$i2/gi;
print $str;
}
}
}
elsif($n1){
for($i1=1;$i1<=$n1;$i1++){
$str = $tpl;
$str =~ s/%N1%/$i1/gi;
print $str;
}
}
####
./script.pl templatefile 2 3