#!/usr/bin/perl
#
# Author: Prabu, School of Computer Science, FIU
#         prabu@cs.fiu.edu
#         6/4/2003
#
# Do NOT edit this file (on Windows)
#
# Examine each *.pl, *.cgi file,
#  and if it contains a path on the first line,
#   it replaces it with user specified string
#

# check for correct number of arguments
if ($#ARGV >= 0) { # in Perl, argcnt is zero for one argument
    die "Usage: $0 [with no argument] \n";
}

print "Enter new path (e.g. /usr/bin/perl ): ";
$newPath = <STDIN>;
$newPath =~ s/\s*$//; # strip trailing white spaces
$newPath = "#!$newPath";

foreach $f (`/bin/ls *.cgi *.pl`) {
  $f =~ s/\s+$//; # strip trailing whitespace
  print " Processing $f\n";
  @line = `cat $f`;
  if ($line[0] =~ /^#!/)
  {
    $line[0] = $newPath;
    open(newF, ">$f") || die "cannot open output file $f - $!";
    for ($idx = 0; $idx <= $#line; $idx++) {
      $line[$idx] =~ s/\s+$//; # strip trailing whitespace
      print newF "$line[$idx]\n";
    }
    close(newF);
  }
}
exit(0);
