#!/usr/local/bin/perl5 -w 
#
# Quick replacement script
#
# Bren Vaughan - 12/2/99

# Get file names

print "Enter file type to replace in : ";
$type = <STDIN>;
chop($type);

# Output names to a file

$dir = "ls $type >file_list";
system($dir);


# Read file names into an array

open (ICA, "<file_list") or die "Could not open the file:$!\n";
while (<ICA>) {
  push(@names, $_)
}
close ICA; 

# Now process each file individually

foreach $a (0 .. $#names) {

  # Read in every line of the file into an array
  
  open (NAM, "+<$names[$a]");
  while (<NAM>) {
    push (@lines, $_);
  }
  close NAM;
  
  # Do the replacement 
  
  open (ALT, "+>$names[$a]");

    # Set the counter to identify which files contain the expression to be replaced
    
    $count=0;
    
  foreach $b (0 .. $#lines) {
    
    # Identify if replacement is occurring in this file
    
    unless ($lines[$b] =~ /^<META/) {
    print ALT $lines[$b];
      $count = 1;
    }
    


  }

  close ALT;

  # State if replacement occurrs
  
   if ($count > 0) {
      print "Replacing in $names[$a]";
    }
  
  # Empty the array before processing next file
  
  @lines = ();

}

# Remove the file with the list of file names

$clean = "rm file_list";
system($clean);
