#!/bin/perl
#
$names = "Names.txt";
$length = "Length.txt";
$temp = "Temp.txt";
$new_names = "New_Names.txt";
$end = "End.txt";

system "ls *.html > $names";
open(IN,"$names") || warn "Can't open $names for read: $!\n\n";
chop(@files=<IN>);
close IN;

foreach $file (@files) {
  $new_file = $file;
  $new_file=~s/\.html/\.shtml/;
  system "wc -l $file > $length";

  open(IN,"$length") || warn "Can't open $length for read: $!\n\n";
  chop(@g=<IN>);
  close IN;

  @f = split(/\s+/,@g[0]);
  $file_length = (@f[1] - 20);

  system "head -$file_length $file > $temp";
  system "rm $file";
  system "cat $temp $end > $new_file";

  open(OUT,">>$new_names") || warn "Can't open $new_names for append: $!\n\n";
  print OUT "$file\n";
  close OUT;
}

system "rm $temp $length $temp";

exit;

