[wplug] Converting Line Terminations

Peter Williams broadway at city-net.com
Thu Feb 7 11:19:34 EST 2002


Hey look, it's something I can reply to! : )
*comes out of lurking*

To set this up in perl, you'd use the following:

#!/usr/local/bin/perl

$filename = $ARGV[0];
open (FILE, $filename);
@file = <FILE>;
close(FILE);
foreach $line (@file) { $line =~ s/\r//; }
$file2 = join ("", @file);
open (FILE2, ">$filename.fixed");
print FILE2 $file2;
close(FILE2);
1;


Dos/Win newline is \n\r
*nix uses only the \n

There's also a text editor I'm really attached to when using Win, 
which lets you convert between dos and *nix formats with one 
double-click (and others may offer a similar feature).  It's called the 
Programmer's File Editor, created by Alan Phillips:
http://www.lancs.ac.uk/people/cpaap/pfe
Even though they aren't continuing development anymore, it's a 
solid program with lots of great features.  Beats out Notepad or 
Wordpad easily.

Hope this helps.  (And sorry if someone beat me to this, I get the 
digest)

All the best,
Peter





More information about the wplug mailing list