Christopher J Bottaro wrote:
hey,I had written a small script for my own use which gets rid of \r and also all weird chars inserted by dos ( or windoze ) in plain text files
i wanna make a perl script that will convert those stupid "\r\n" dos newlines to good unix "\n" newlines...=) the problem isn't really a perl problem, but a general programming problem that i've always kinda wondered about.
so i guess what i'm gunna do is open the file, read in a line, search for "\r\n", if its there, replace it with just "\n", then write the new (edited) line to a new file. my problem is this...if the file is 10 megs, then not only is the program gunna read a 10 meg file, but write one as well. is there not a better way to do this?
i can't really remove the "\r" in situ because as far as i understand, a file is just an array of bytes and if i remove the "\r", i'd have to shift everything else down one byte.
thanks for the tips,
-- christopher
Do not use it on files which are not plain text
#!/usr/bin/perl
#
# This file is used to clean the special chars && ^M chars from dosfiles
#
#
open(IN,$ARGV[0]) || die "Could not open file $ARGV[0] $! ";
while(defined($c = getc(IN))){
next if((($i =ord($c)) > 126) || ($i == 13 ));
$content .= $c;
}
close IN;
open(OUT,">$ARGV[0]") || die "Could not open file $ARGV[0] $! ";
print OUT $content;
close OUT;
print STDERR " $ARGV[0] cleaned \n";
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]