#!/usr/bin/perl
#
# Author: Prabakar, School of Computing and Information Sciences, FIU
#         prabakar@cis.fiu.edu
#         7/6/2014
#
# Do NOT edit this file (on Windows)
#
# If any of the cript file is edited using Windows text editors
# there will be a CR (carriage return character) at the end
# of each line on the script file. This causes problem in executing
# the script file on any Unix/Linux system.
# This scrip file examines the first argument (file)
# in the current directory, removes the extra CR character
# (if present) and rewrites the modified content on the same file.
#

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

$f = $ARGV[0];
$f =~ s/\s+$//; # strip trailing whitespace
@line = `cat $f`;
open(newF, ">$f") || die "cannot open output file $f - $!";
for ($idx = 0; $idx <= $#line; $idx++) {
  $line[$idx] =~ s/\n$//; # strip LF from the end of line
  $line[$idx] =~ s/\r$//; # strip CR from the end of line
  print newF "$line[$idx]\n";
}
close(newF);
print " All CR characters from file $f have been removed\n";
exit(0);
