On Fri, 30 Aug 2002, Omanakuttan wrote:

> I am trying to strip off ^Ms from a number of text files.
> The following does not seem to work. any suggestions?
> 
> my $filename  ;
> while ($filename = shift) {
>  open (INF, $filename) or die "Could not open $filename. $!" ;
>  my @file = <INF> ;
>  close INF ;
>  open (OUT, ">$filename") or die "Could not open $filename. $!" ;
>  foreach my $line (@file) {
>    $line =~ s/\015\012// ;        ## <===== something wrong with this?

This regex is fine

>    print OUT $line,"\n" ;
>  }
>  close OUT ;
> }

I guess your filenames are in @ARGV array, your shift inside the while 
suggests it either @ARGV or @_. If it is @ARGV you can do this

$^I = '~';
while (<>) {
  s/\015\012/\n/;
}

This will replace CRLF with "\n" in your input files and also create a 
backup of your original file as <filename>~.

A oneliner for this is
perl -i~ -pe 's/\015\012/\n/' <your files>








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

Reply via email to