Ramprasad A Padmanabhan wrote:
> 
> 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
> 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;

Reading a character at a time is very inefficient.

> }
> close IN;
> open(OUT,">$ARGV[0]") || die "Could not open file $ARGV[0]  $! ";

Closing and opening the file again is inefficient.

> print OUT $content;
> close OUT;
> print STDERR " $ARGV[0] cleaned \n";


#!/usr/bin/perl -w
use strict;
#
# This file is used to clean the special chars && ^M chars from dosfiles
#
#
open IN, "+<$ARGV[0]" or die "Could not open file $ARGV[0]  $!";
read IN, $_, -s IN;
tr/\x0D\x7F-\xFF//d;
seek IN, 0, 0;
truncate IN, 0;
print IN;
close IN;
print STDERR " $ARGV[0] cleaned \n";




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to