#! /usr/bin/perl -w

use strict;

{
   my ($file, $line, $contents);
   
   # process files
   foreach $file (@ARGV) {
      if (-f $file) {
         print("processing $file\n");
   
         # read file contents
         open(FILE, $file) or die("can't open $file for read");
         $contents = '';
         while ($line = <FILE>) {
            $contents .= $line;
         }
         close(FILE) or die("can't close $file after read");
   
         # change patterns throughout
         $contents =~ s/pattern1/pattern2/g;
         $contents =~ s/pattern3/pattern4/g;
   
         # write out edited file contents
         open(FILE, ">$file") or die("can't open $file for write");
         print(FILE $contents);
         close(FILE) or die("can't open $file for write");
      }
   }
}
