[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] File conversion script problem



On Mon, 1 Feb 1999 10:20:10 -0700, Ero Brown wrote:

>I wrote the following script to convert files from one line
>ending format to another (i.e., Mac2Unix, Dos2Mac, etc.).
>
>1) Please let me know if you know of a better script to do
>   this sort of thing.

"Better"? It depends on the size of your files. For relatively small
files, e.g. HTML files downloaded on PC (which may contain the CR+CR+LF
sequence), I use something like this (actually an untested variation):

	$\ = "\n"; # or whatever you want the line end to become
	while($file = shift) {
		local $/; # whole file
		open(FILE,$file) or do {
			warn "Can't open file $file:$!\n"; 
			next;
		}
		my @line = split /\015\015?\012|\015|\012/,<FILE>;
		foreach(@line) {
			print;	#including newline (see first line)
		}
		my $linecount = @line;
		local $\;
		print STDERR "File $file: $linecount lines\n";
	}

   HTH,
   Bart.

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch