#!/usr/local/bin/perl # read in Windows created text files and fix end of line characters unless ($#ARGV eq 0) { print "ERROR: give directory name to process as argument.\n"; exit; } # read directory name from command line: $indir = $ARGV[0]; # check it: print "read from command line: $indir\n"; opendir(DIR, "$indir") || die "Can't open $indir: $!\n"; @in_files = readdir(DIR); closedir(DIR); # make list of only *.html files: foreach $one (@in_files) { if ($one =~ /\.html$/) { push(@html_files,$one); } } # check it: print "\@html_files:\n @html_files\n"; # now loop over the html files and translate end of file characters in each: foreach $hfile (@html_files) { # print "processing $hfile ...\n"; $infile = $indir . '/' . $hfile; print "processing $infile ...\n"; &read_input; &convert_end_olines; &write_output; } #///////////////////////////////////////////////////////////////// #///////////////////////////////////////////// subroutines: #//////////////////////////////////////////////////////////////// sub read_input { open(HFILE,"$infile") || die "can't open $infile"; # must now reinitialize $line for each new file! $line = ""; while () # while lines to read { $line=$line.$_; # concatenate with next line } close(HFILE); ## ----------------- ## remove newlines ## ----------------- # #$_=$line; #tr/\n/\ /; #$line=$_; ## check: #print "\$line:\n"; #print "$line\n"; #print "---------------------------------------\n\n"; } # end "sub read_input" #---- sub convert_end_olines { $_=$line; tr/\015/\ /; $line=$_; } # end "sub convert_end_olines: #---- sub write_output { # make temporary backup copy: # $backup = $hfile . '-bak'; $backup = $infile . '-bak'; system("cp $infile $backup"); # open output filehandle and write to it: $outfile = $infile; open(OUT,">$outfile") || die "Can't open file $outfile: $!"; print OUT "$line"; close(OUT); } __END__