So, I'm looking at the files in hexedit, and some of them 
are coming out with 0d 0d 0a patterns.
I would think the following would correct lone 0d and lone 0a
to a full return, but it isn't. 
 
Can anyone see why?
 
 

 unless(open(FH, "+< $filename")) {
  die "Error: unable to open $filename for conversion";
  return;
 }
 $/ = undef;
 my $input = <FH>;
 
 # convert any \0a not preceded by \0d to \0d\0a
 $input =~ s{(?<!\x0D)\x0A}{\x0D\x0A}g;
 # convert any \0d not followed by \0a to \0d\0a
 $input =~ s{\x0D(?<!\x0A)}{\x0D\x0A}g;
  
 seek(FH, 0,0);
 print FH $input;
 truncate(FH,tell(FH));
 close(FH) or die "ERROR: unable to close '$filename'";
 

________________________________

From: Ronald J Kimball [mailto:[EMAIL PROTECTED]
Sent: Tue 11/7/2006 11:54 AM
To: Greg London
Cc: Boston Perl Mongers
Subject: Re: [Boston.pm] unix to dos, intelligently



On Tue, Nov 07, 2006 at 11:43:49AM -0500, Greg London wrote:
> If I run unix2dos twice on a file,
> it will fix the bad lines, but the lines
> that were OK end up with empty
> lines in between every line.

In fact, you may have extra carriage returns from the lines that were
correct originally.


> Anyway, I think I need a unix2dos
> script that will just fix the unix newlines
> without modifying the dos newlines.
> 
> but I'm not exactly sure.
> Some instruction and some code
> would probably be helpful.

A Unix newline is just a line feed, "\x0A", while a Windows newline is a
carriage return followed by a line feed, "\x0D\x0A".  So to convert a mixed
file to a Windows file, you only want to replace "\x0A" when it's not
preceded by "\x0D".

perl -pi -e 's/(?<!\x0D)\x0A/\x0D\x0A/g'


Ronald


 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to